function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hemant ChandHemant Chand 

Unable to create case due to "UNABLE_TO_LOCK_ROW" error

Hello,

Process 1 = One process is running in org which upserts the Assets records. Asset has the lookup of Account so accounts are also locked in this process.

Process 2 = Email to Case is configured in Salesforce org. Case has a lookup of account and at the time of case creation, account is assigned to the Case. So Accounts are also locked by case creation process.

Now, when both the processes run at the same time, I get the error - "This error occurred: UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record or 1 records:".

With this problem, cases are not created in Salesforce so we are missing some customers cases.

Could you please let me know the next step to remove this error.

Thank You!!
Best Answer chosen by Hemant Chand
VinayVinay (Salesforce Developers) 
Hi Hemant,

When you have multiple jobs running that update the same set of records, it's recommended to lock the records using the update keyword. It will ensure that the record is locked and no other job can update the same record at that point in time. The conflicting job will then wait untill the locking on the record is released and then perform the required operation. This will avoid conflicts between jobs that are running concurrently and will not throw up this exception. 

Check below reference for more details.

https://help.salesforce.com/articleView?id=000338933&type=1&mode=1
https://salesforce.stackexchange.com/questions/20921/can-anybody-explain-the-unable-to-lock-row-error/20923

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,