Reputation: 53
I have to upsert large amount of data to opportunities in salesforce. Used batch commit in first batch step. The result of Upsert Bulk is the list of Upsert Result which has success,id,error,fields.
Iterating over this result , to check for failed record (success is false), now I wanted to send the error and the original payload to email.
Example : inputpayload :[rec1,rec2,rec3] UpsertResult[success:true,success:false errors:invalid field,success:true]
I want to send an email saying rec2 has failed due to error invalid field.
Any help would be highly appreciated.
Upvotes: 0
Views: 827
Reputation: 1
The order of salesforce opeation result will be maintained as same as per Input order. Store the input in a Hashmap with Id as key and entire input as value, before the batch step. After the batch step, Iterate over the result and collect the Ids when result has status as false.
Now you can easily retrieve failed Id's data from the hashmap, by passing Id. Code snippet
def inputPayloadForReprocess =[];
//logic to build error records for reprocess
for(int i=0; i < payload.size() ; i++ ){
if(payload.get(i).toString().contains("success='false'")){ //check for salesforce failures
inputPayloadForReprocess.add(message.getInvocationProperty("storePayload").get(i));
break;
}
}
Upvotes: 0