1

This question already has an answer here:

I am trying to insert new records in Salesforce using data loader, but getting the below error - Error received from salesforce.com. Fields []. Status code [UNABLE_TO_LOCK_ROW]. Message [unable to obtain exclusive access to this record].

I thought this happens only during update, but why it is happening in Insert

marked as duplicate by Pranay Jaiswal, battery.cord, Raul, glls, Dave Humm Dec 13 '18 at 9:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Are you inserting child records? If child cannot get access to parent it throws that error. – Pranay Jaiswal Dec 11 '18 at 14:22
5

There are lots of situations where an insert can cause a record lock against the parent of the inserted record, or even against third records. Inserting Task, for example, can lock the WhoId, WhatId, and AccountId.

The Record Locking Cheat Sheet is an excellent guide to what facets of your data have the highest likelihood of lock contention.

Fixing this error is generally heuristic - you need to understand the cause of the underlying issue and then apply one or more techniques to minimize the locking risk, but there's no switch you can throw to make it go away.

The two techniques that are often applicable are

  • Order your incoming data by parent record Id, to prevent records in different batches from contending for the lock on the parent.
  • Ensure that the Data Loader is configured to utilize the Bulk API in Serial mode, rather than Parallel mode.

In many cases (such as when a record has exactly one parent) you won't need to do both, just one or the other. Situations with extreme data skew and records that have more than one parent are more complex, however.

Depending on the situation, it's possible you might have to undertake more drastic interventions, like scheduling a maintenance window to prevent users from themselves seeking to work with affected records, or disabling triggers and other automation on the records you're importing.

Spend some time with the locking cheat-sheet to identify your core issue first, though, and try each of the two points above first before you go that far.

  • bookmarking that cheat sheet posthaste – Derek F Dec 11 '18 at 14:31

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