Not long time ago I decided to use insert, update, delete methods of Database class and its optional 2nd parameter allOrNone with false as value.

But I found calling getId from the result does not return an Id for a failed record. It makes sense for insert, but update and delete?

How can I process partial success for insert, update and delete operation?


2 Answers 2


You can compare the list of ids you attempted to update/delete to the list of id's you collect with getid() that succeeded to determine which records failed.

If you iterate on the ids in your original collection, you can use the Error Class getMessage() method to determine the actual error for each record Id which didn't update/delete successfully.

  • Yes, this is the solution. I didn't think about this, because I created a method to which I pass SaveResult array and where I tried to get all information. Mar 19, 2017 at 22:51

Returns the ID of the sObject you were trying to insert or update.

If this field contains a value, the object was successfully inserted or updated. If this field is empty, the operation was not successful for that object.

More details are listed at this question,
Database.SaveResult.getId() returns null

Ref : https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_saveresult.htm

  • I saw this. This fact leads me to write a question on SO. Mar 19, 2017 at 22:49

Not the answer you're looking for? Browse other questions tagged .