7

During the process of loading 90,000 opportunities into Salesforce using the Bulk API, I get this error:

UNABLE_TO_LOCK_ROW:unable to obtain exclusive access to this record or 124 records...

After the error there is a long list of Account record Id's.

  • I am using a batch size of 10,000
  • All processes, flows and work flows are off
  • All triggers are disabled.

I am unsure why this is happening...

Questions

  1. Why am I getting this error?
  2. What can I do I better understand the error?
  3. How might fix it?

1 Answer 1

15

A great resource for understanding row locking situations is the Record Locking Cheat Sheet (PDF link). Note at the top of page 2 that insert, update, and delete of Opportunities locks the parent Account.

Since your batch job is running in parallel across its batches, the batches can independently attempt to gain locks on the same Account, resulting in this exception.

There's a couple of different strategies you can apply.

  1. Sequence the inbound Opportunities by Account Id. This will limit lock contention between batches running in parallel, although it may or may not be enough to completely eliminate it if Opportunities on the same Account sometimes overlap batch boundaries.
  2. Ask the Bulk API to process in serial mode to eliminate contention between batches (see here for details on this configuration in the Salesforce Data Loader; other clients might have slightly different setup).
1
  • 4
    You sir are a gentleman and a scholar.
    – Robs
    Commented May 8, 2019 at 13:35

You must log in to answer this question.

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