我刚刚收到了一封关于我在生产环境中的触发器的开发人员脚本异常电子邮件:
Apex script unhandled trigger exception by user/organization: 00590000002GfMD/00D90000000cIze
SetContactDonorCampaign: execution of BeforeInsert
caused by: System.DmlException: Update failed. First exception on row 0; first error:
MISSING_ARGUMENT, Id not specified in an update call: []
Trigger.SetContactDonorCampaign: line 25, column 1
该错误没有给我它失败的记录的任何 id,这有点烦人。触发器本身仅识别何时创建 Payment_Information__c 记录并填充查找 Contact__c,并在该联系人上设置一个多选选项列表以包括“捐赠者”(如果还没有)。
trigger SetContactDonorCampaign on Payment_Information__c (before insert,before update) {
for(Payment_Information__c donation : Trigger.new)
{
Contact reg = new Contact();
if(donation.Contact__c != NULL)
{
reg = [SELECT id, Campaign__c FROM Contact WHERE Id = :donation.Contact__c];
String regCampaign = '';
if (reg.Campaign__c != NULL)
{
if (!reg.Campaign__c.contains('Donor'))
{
regCampaign = reg.Campaign__c + ';Donor';
} else {
return;
}
} else {
regCampaign = 'Donor';
}
reg.Campaign__c = regCampaign;
}
if (reg != NULL)
{
update reg;
}
}
}
如果没有要查找的特定记录(系统甚至没有与此错误匹配的修改日期的付款信息记录),有什么关于这里失败的建议吗?