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
Mohsin.RazaMohsin.Raza 

Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []

I have a customer who is reporting the below error when my code creates Task record.

Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] 

The whoid for task is usually a contact and whatid is opportunity or case. This is an intermittent issue and is not easily reproducebale. The strange thing is that this occurs when inserting a new task record so we dont know which record is causing this to fail as the task record could not be lock at this point as its not yet created. Can it be that one of the parent records (contact or opportunity) is locked?
v varaprasadv varaprasad
Hi Mohsin,

Hi there is some kind of recussion going on like 
1.)Trigger is calling another trigger which is trying to update same record
2.)batch is calling another trigger which is trying to update same record
 
So just check all your active actions and see if any 2 of them are clashing with each other.

More info :   https://salesforce.stackexchange.com/questions/20921/can-anybody-explain-the-unable-to-lock-row-error

Hope This helps,
Please let me know in case of any further assistance.


Thanks
Varaprasad
Mohsin.RazaMohsin.Raza
Hi Varaprasad,

I will review existing triggers and batch processes.

Thanks,
Mohsin
Eric Kintzer 10Eric Kintzer 10
Inserting Task creates locks on parent whoId, whatId, accountId, custom object lookup Ids - Locks only occur if the Status is Completed and the ActivityDate is not null.  See Locking Cheatsheet (http://resources.docs.salesforce.com/194/0/en-us/sfdc/pdf/record_locking_cheatsheet.pdf)