[SalesForce] Meaning of Error : Maximum number of duplicate updates in one batch (12 allowed)

Lately I have came across an Error as given below.

Maximum number of duplicate updates in one batch (12 allowed). Attempt to update Id more than once in this Api call

I was able to solve the issue by re-creating the file with unique values. But I want to know the exact meaning/reason for this error.
So My confusion is

When salesforce says that Maximum number of duplicate updates in one batch (12 allowed) Does it mean that,

  • its not allowed if I have 26 records in a file where I have 13 unique records and each one of them has 1 got duplicate
    records!?

  • its not allowed if I have 26 records in a file where 1 record is duplicated 13 times and rest of the 13 records in the file are unique.

Best Answer

I got a similar error when I was creating test data for a Unit Test. I tried inserting records who has a Process Builder Flow who updates their Parent's Field if a condition was met. I had more than 12 children per parent in my insert which caused this error.

My message to Salesforce....WOW! How silly! Their Process Builder is not bulkified IMHO. The Process Builder must run each record through the Process and collect any records for updating so it can do a bulk update at the end. However, instead of storing records for updating as a Map<Id, SObject> (which would let the last Parent win), they store the records as a SObject[] (which is still last record wins) and just add records as they go. Talk about asking for trouble.

An even better solution is to store records for update as Map<Id, SObject> and then as the Process Builder processes the batch, the Process Builder checks:

  • If records.get(record.Id) == null, put the record in the Map.
  • Then, for each Field to update: records.get(record.Id).put(field, value)

This would allow the last set Field per record to win (desirability is TBD).

Related Topic