By calling the update calls, I saved all the success and failed records. I notice that for success you can get the id of the particular records, however not in those failed records. How am I able to determine which one is failed?


create/update/delete/upsert all return a result array that is poisitionally matched against the input array, i.e. if you call update with 5 accounts, a[0] .. a[4], you get back 5 save results, the save result at index 0 is for the first account in the request, then 2nd save result is for the 2nd account in the request and so on. So you can do something like

Account [] accounts = someAccountsToUpdate();
SaveResult [] sr = binding.update(accounts);
for (int i=0; i < sr.length; i++) {
  Console.writeln("account update {} returned status {}", accounts[i], sr[i]);
  • Within the loop, look for the success boolean. If it is false, also check the errors collection of SaveResult. – Daniel Ballinger Nov 14 '14 at 8:05
  • I tested this, and works fine. the only thing why I need the id is because for me to reference it to an object and get the specific field. example the name of each record. This works for single update but what if you have multiple update for different objects? What I did for the multiple update call for different object is I add them in a list as range. – rpm07 Nov 14 '14 at 9:10

If you're inserting records you won't have IDs of the failed ones obviously as the record did not get inserted which means no ID has been assigned to it. However if you're upserting or updating, you must specify an ID to the record before you perform the DML. That being said, if a subset of records fail and you have a list of IDs of the ones that succeeded, you can loop through the original list and check against the succeeded list, the difference will be a subset of records that failed and you already would have the IDs specified.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.