我收到此错误,并且两个联系人的合并无效。任何帮助表示赞赏。
以下是我在日志中收到的错误之一:" 23:10:48:243 EXCEPTION_THROWN [14] | System.DmlException:更新失败。第0行的第一个例外,标识为a0A1a0000095ZDxEAM;第一个错误:ENTITY_IS_DELETED,实体被删除:[]"
这是我的合并类(自定义字段是联系人查找):
public class BatchMerge implements Database.Batchable<sObject> {
public Database.QueryLocator start(Database.BatchableContext context) {
return Database.getQueryLocator([SELECT Contact_to_Merge_Into__c, Contact__c FROM Contact_Merge_Record__c]);
}
public void execute(Database.BatchableContext context, Contact_Merge_Record__c[] records) {
for(Contact_Merge_Record__c record: records) {
try {
Database.merge(new Contact(Id=record.Contact_to_Merge_Into__c), record.Contact__c);
record.Merge_Status__c = 'Success';
} catch(exception e) {
record.Merge_Status__c = 'Failed';
}
}
update records;
}
public void finish(Database.BatchableContext context) {
}
}
答案 0 :(得分:0)
当您致电Database.merge(new Contact(Id=record.Contact_to_Merge_Into__c), record.Contact__c);
时,您的record
对象会被合并并删除。然后,您正在尝试通过record.Merge_Status__c = 'Success';
更新其状态。显然,如果对象已被删除,则无法更改其字段。