gpt4 book ai didi

salesforce - 第一个错误 : INVALID_CROSS_REFERENCE_KEY, 分配给 ID:所有者不能为空:[OwnerId]

转载 作者:行者123 更新时间:2023-12-04 08:36:35 28 4
gpt4 key购买 nike

我正在为我的 Controller 编写测试。为此,我必须在测试数据库中插入一个事件。

我的测试方法是:

static TestMethod void Test1_TestInsertWithValue()
{
Meeting_Master__c master = new Meeting_Master__c();
Event event = new Event();
Profile p = [SELECT Id From Profile WHERE Name='Standard User'];
User u2 = new User(Alias = 'newUser', Email = 'newuser@testorg.com', EmailEncodingKey = 'UTF-8', LastName = 'Testing',
LanguageLocaleKey = 'en_US', LocaleSidKey='America/Los_Angeles', UserName='newuser@testorg.com', ProfileId=p.Id);

event.OwnerId = u2.Id;
event.StartDateTime = datetime.newInstance(2008, 12, 1);
event.EndDateTime = datetime.newInstance(2008, 12, 30);
event.subject = 'call';
event.WhatId = master.Id;
insert master;
insert event;
...........
}

当插入事件发生时,我面临这个错误:

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Assigned To ID: owner cannot be blank: [OwnerId]

我该如何纠正这个错误?

最佳答案

您忘记在 event.OwnerId =u2.Id; 行之前插入 u2

关于salesforce - 第一个错误 : INVALID_CROSS_REFERENCE_KEY, 分配给 ID:所有者不能为空:[OwnerId],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14867242/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com