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.