When a Salesforce record is being updated or created, a lock is placed on that record to prevent concurrent operations from causing data inconsistencies. These locks normally last a few seconds. However, a transaction can wait a maximum of 10 seconds for a lock to be released before timing out and throwing the "Unable to lock row - Record currently unavailable" error. Common triggers for this error include concurrent DML operations, Apex triggers, Bulk API imports, and Master-Detail relationship updates.
To resolve "Unable to lock row" errors, identify which scenario below applies to your use case and follow the corresponding guidance. For a comprehensive reference on how and when Salesforce places record locks, consult the Salesforce Platform Record Locking and Concurrency documentation.
When an email is processed by Email-to-Case, triggers on the EmailMessage object or related objects (such as the parent Account) attempt to lock those records. If another process already holds a lock on these records and the Email-to-Case processing must wait more than 10 seconds, a timeout occurs and this error is thrown.
Resolution: Review triggers on EmailMessage and related objects. Reduce trigger execution time where possible.
When an After Insert Apex Trigger runs on a child record (such as a Task) related to a parent record (such as an Account), Salesforce locks the parent Account record during the child record creation. If the trigger runs for more than 10 seconds, any concurrent attempt to update the parent Account will fail with the locking error.
Example scenario:
Resolution: Reduce the execution time of Apex triggers. Avoid or minimize the use of Locking Statements in triggers. Note: Apex Tests can also cause locks if run against production data.
When inserting or updating records through the Bulk API, batches are processed in parallel by default. If two parallel batches contain records pointing to the same parent record, both batches attempt to lock the parent record simultaneously, which can cause the "unable to lock row" error.
Resolution: Use one or more of the following approaches:
If a Master record has a very large number of Detail child records (thousands), editing any Detail record locks the Master record. With many child records being edited concurrently by users, the probability of lock contention on the Master record increases significantly.
Resolution: Reduce the number of child records on a single parent by distributing child records across multiple parent records. Review Record Level Locking strategies.
000387767

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.