Salesforce Bulk Upsert 抛出重复错误
Salesforce Bulk Upsert throws Duplicate error
我正在对 SF Bulk 中的重复错误场景进行研发 API,发现不知何故我无法同时对具有相同(外部 ID)的联系人执行插入和更新操作单批。
我收到重复错误。截屏供参考
https://www.screencast.com/t/ReE41vuzb
当批次包含不同的外部 ID 时,我没有任何错误。但是当在一个批次中重复外部 ID 时,我收到以下错误。
{
"success":错误,
"created":错误,
"id":空,
"errors":[{
"message" : "Duplicate external id specified: 7401",
"fields" : [ "Origami_ID__c" ],
"statusCode" : "DUPLICATE_VALUE",
"extendedErrorDetails":空
}
虽然在目标端没有重复。
您只需要具有相同唯一 ID 的多条记录中的最后一条记录。
为此遵循以下逻辑:
//Create Map and populate the map with last record having unique id
Map<String,MyObject__c> mapWithUniqueIdMyObject = new Map<String,MyObject__c>();
MyObject__c currentObject;
for(Integer currentPosition = myObjectListWith5000Records.size(); currentPosition >=0 ;currentPosition--){
currentObject = myObjectListWith5000Records.get( currentPosition );
if( !mapWithUniqueIdMyObject.containsKey(currentObject.Origami_ID__c) ){//If the map does not contain any object with unique id then put the object in the map
mapWithUniqueIdMyObject.put( currentObject.Origami_ID__c, currentObject );
}
}
upsert mapWithUniqueIdMyObject.getValues();
我正在对 SF Bulk 中的重复错误场景进行研发 API,发现不知何故我无法同时对具有相同(外部 ID)的联系人执行插入和更新操作单批。
我收到重复错误。截屏供参考
https://www.screencast.com/t/ReE41vuzb
当批次包含不同的外部 ID 时,我没有任何错误。但是当在一个批次中重复外部 ID 时,我收到以下错误。 { "success":错误, "created":错误, "id":空, "errors":[{ "message" : "Duplicate external id specified: 7401", "fields" : [ "Origami_ID__c" ], "statusCode" : "DUPLICATE_VALUE", "extendedErrorDetails":空 }
虽然在目标端没有重复。
您只需要具有相同唯一 ID 的多条记录中的最后一条记录。
为此遵循以下逻辑:
//Create Map and populate the map with last record having unique id
Map<String,MyObject__c> mapWithUniqueIdMyObject = new Map<String,MyObject__c>();
MyObject__c currentObject;
for(Integer currentPosition = myObjectListWith5000Records.size(); currentPosition >=0 ;currentPosition--){
currentObject = myObjectListWith5000Records.get( currentPosition );
if( !mapWithUniqueIdMyObject.containsKey(currentObject.Origami_ID__c) ){//If the map does not contain any object with unique id then put the object in the map
mapWithUniqueIdMyObject.put( currentObject.Origami_ID__c, currentObject );
}
}
upsert mapWithUniqueIdMyObject.getValues();