0

A duplicate ID in my list of SObjects "businessPartnerListToUpdate"

Database.SaveResult[] saveResultList = Database.update(businessPartnerListToUpdate, false);

causes an Exception to be thrown:

System.ListException: Duplicate id in list: 0011r00001mIDEAAA4

I was having the assumption that since I set allOrNone to false, the rest of the records will still succeed, but this is not the case. Why is this so?

2
  • Your assumption is true, it will process all records and you will get the list of errors. From which you can find out the duplicate records salesforce.stackexchange.com/questions/149431/…
    – Saroj Bera
    Apr 10 '18 at 12:25
  • @SarojBera That question is about errors caused by duplicate rules, not duplicate Ids in the DML list.
    – David Reed
    Apr 10 '18 at 13:13
2

It's true that allOrNone set to false will result in inserting or updating those records that don't have errors associated with them. However, in this case, the exception that's raised has to do with the whole DML operation, not with a single record.

I think of this error as Salesforce indicating that there is an internal inconsistency in what it was asked to do, and hence it performs no work at all.

The typical remedy for this error is to accumulate records to be updated in a Map<Id, Sobject>, and then do

Database.update(myMap.values(), false);

This will ensure that each Id is present only once.

1
  • yes, I think so too.. that this is not an error it can (or will) handle partially for some records and let other records succeed. Basically it will not show any preference between the first duplicate and the second duplicate and fails both. thanks for confirming. Apr 11 '18 at 5:49

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.