UNABLE_TO_LOCK_ROW in Salesforce: what it means and how to fix it

Short answer: UNABLE_TO_LOCK_ROW means Salesforce couldn't get exclusive access to a record because another transaction was already holding a lock on it, or on its parent, for longer than Salesforce is willing to wait. It's caused by concurrency, not by bad data, so the same records usually succeed when retried with less contention.

Every insert or update in Salesforce runs inside a transaction that locks the rows it touches until it commits. If a second transaction needs one of those rows, it waits. Salesforce waits around ten seconds; if the lock still isn't free, the second transaction fails with:

UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record or 1 records

The record named in the error is often not the one you were saving. It's frequently a parent record that your save had to lock along the way.

Why it happens

During data loads, sandbox seeding and replication, the usual causes are:

  • Parallel batches sharing a parent. Bulk API jobs process batches at the same time. If Contacts for one Account land in several batches, each batch tries to lock that Account, and they queue behind each other.
  • Master-detail and roll-up summaries. Saving a detail record locks its master so roll-up summary fields can be recalculated. Loading many details for one master is a classic trigger.
  • Data skew. One parent with tens of thousands of children (an "Unassigned" Account, a catch-all Campaign), or one user owning a huge share of records, turns every load into contention for the same row.
  • Automation touching the parent. Triggers, flows and process automation that update the parent record on each child save widen the lock and hold it longer.
  • Sharing recalculation. Ownership or role changes can recalculate sharing on large numbers of records, holding locks while other jobs run.

How to fix it

  1. Sort records by parent ID before loading. Grouping children of the same parent into the same batch means one batch takes the lock instead of several competing for it.
  2. Use smaller batches. Smaller batches hold locks for less time and give other batches a chance to proceed.
  3. Retry the failed rows. Because the data is valid, re-sending only the failed records after the load finishes usually clears most of them.
  4. Reduce parallelism when you must. Bulk API 1.0 supports a serial concurrency mode. It is slower, but no two batches run at once.
  5. Fix the skew. Spread children across more parents, or assign records to more than one owner, so no single row is a hot spot.
  6. Quiet the automation. Check which triggers and flows update the parent on child save, and whether that work can be deferred or skipped for integration users during loads.

How Syntharil handles it

Syntharil classifies UNABLE_TO_LOCK_ROW as an org state error: nothing is wrong with the generated or copied values, so it isn't something to fix in your configuration. When it seeds records, it sorts them by their parent lookups before batching and keeps batch sizes controlled, which reduces how often batches compete for the same parent. Batches are independent, so one batch hitting a lock doesn't stop the rest of the load, and failed rows are reported with Salesforce's own error message so you can see exactly which records to retry.

FAQ

Is UNABLE_TO_LOCK_ROW caused by bad data?

No. The record itself is usually fine. The error means a different transaction was holding a lock at the same moment, so retrying the same rows later, or with less parallelism, normally succeeds.

Why do child records lock their parent Account?

Saving a child in a master-detail relationship locks the parent so Salesforce can keep roll-up summaries and sharing consistent, and many lookup relationships lock the parent too. When thousands of children of one parent load in parallel batches, those batches queue for the same parent lock.

Does Bulk API 2.0 have a serial mode?

No. Bulk API 2.0 manages batching and parallelism itself. If you need strictly serial processing, Bulk API 1.0 jobs accept a serial concurrency mode, at the cost of a slower load.

How many children per parent is too many?

Salesforce's guidance on data skew is to keep any one parent below about 10,000 child records. Above that, lock contention and sharing recalculation get noticeably worse during loads.

Can Apex prevent this error?

Apex can lock rows deliberately with SELECT ... FOR UPDATE so its own transactions queue in a predictable order, and it can retry on failure. It can't stop other transactions from holding locks.

All Salesforce errors →

Try Syntharil free