Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Database.SaveResult and Database.update(..., false) for the very first time and ask myself how to get the Id of the record where a dml has failed.

I expected Database.SaveResult.getId()` to give me that answer but is empty when the dml failed.

Help ;-)!

share|improve this question
up vote 23 down vote accepted

We can use List index Property to get the Id of the failed record .The Index of the List which we are updating and also the result set retrieved has the same index .Using the above property for our advantage we can draft a pseduo code as below

List<Database.SaveResult> updateResults;
        updateResults = Database.upsert(arudate, false);
      for(Integer i=0;i<updateResults.size();i++){

            if (updateResults.get(i).isSuccess()){
            else if (!updateResults.get(i).isSuccess()){
                // DML operation failed
                Database.Error error = updateResults.get(i).getErrors().get(0);
                String failedDML = error.getMessage();
                arudate.get(i);//failed record from the list
                                    system.debug('Failed ID'+arudate.get(i).Id);


share|improve this answer
does anyone understand why the failed ones don't include the ID? – Phil B Oct 5 '15 at 21:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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