gpt4 book ai didi

salesforce - 插入前引线触发不返回 Lead.Id

转载 作者:行者123 更新时间:2023-12-03 03:11:21 27 4
gpt4 key购买 nike

我有一个简单的触发器,可以在创建或更新潜在客户时从潜在客户对象中提取数据并将其放入自定义“财务”对象中。由于某种原因,Trigger.new[i].Id 在插入之前触发的触发器中返回 NULL。

我快要疯了,因为我看不出 Id 为 NULL 的任何原因...这是我的代码:

trigger FinanceNew on Lead (before insert) {

Map<String,User> userList = new Map<String,User>{};

// Places each returned user into a map with their sfID as the key
for(User tmp : [SELECT Id,Name,Email,Phone FROM User]){
userList.put(tmp.Id,tmp);
}

for(integer i = 0; i<Trigger.new.size(); i++){

string leadName = null;

if(Trigger.new[i].FirstName != ''){
leadName = Trigger.new[i].FirstName + ' ' + Trigger.new[i].LastName;
}else{
leadName = Trigger.new[i].LastName;
}

User ownerInfo = userList.get(Trigger.new[i].OwnerId);

ID leadId = Trigger.new[i].Id; // THIS IS RETURNING NULL!!

Finance__c financeRecord = new Finance__c(

Name = leadName,
Lead__c = leadId,
Lead_Email__c = Trigger.new[i].Email,
Lead_Phone__c = Trigger.new[i].Phone,
Lead_Owner_Name__c = ownerInfo.Name,
Lead_Owner_Email__c = ownerInfo.Email,
Lead_Owner_Phone__c = ownerInfo.Phone

);

insert financeRecord;

}

}

预先感谢您提供的任何帮助!

乔什

最佳答案

For some reason, the Trigger.new[i].Id is returning NULL in the trigger which fires before insert.

SFDC 记录在插入之前没有 ID。插入过程会创建 ID。您可能想在插入后使用。

关于salesforce - 插入前引线触发不返回 Lead.Id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9491199/

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