+ Start a Discussion
msreekmmsreekm 

UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record

In my afterinsert trigger  on Lead , I want to update one of the fields in the current Lead records being inserted .I cannot do this in before insert since Iam dependent on the ID's of the newly inserted leads .

 

Getting the below error-

 

LeadTrigger: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00QT0000005JQ05MAG;

first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []

 

any one encountered this issue?

Best Answer chosen by Admin (Salesforce Developers) 
NaishadhNaishadh
You cannot update the same record in after insert trigger. Use @future method to over come the problem.

All Answers

NaishadhNaishadh
You cannot update the same record in after insert trigger. Use @future method to over come the problem.
This was selected as the best answer
sfdcfoxsfdcfox
You can't perform a DML action on a record that is currently the target of a trigger-- it is locked for editing until the trigger stack completes. You should be able to use a @future routine to update the lead at some future point in time; pass a list of ID values to a function marked as @future, and at some point in the near future after that routine, it will update the lead without a problem.
msreekmmsreekm
I got this working with @future, thanks for the replies.
allen.zhangyilunallen.zhangyilun

Can you paste your code here, then we can know how to use the @future.

nagalakshminagalakshmi

Hi,

 

I am also facing the same issue. when i insert the records from parent to child object through batch apex class. i am getting error as 'First error: Insert failed. First exception on row 0; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: []'. But it is working fine in full sandbox which is copy of live. But i am getting error in live. How can i solve this error. Please help me.

 

 

Thanks,

Lakshmi

d.tejdeep@nicomatic.ind.tejdeep@nicomatic.in

i am getting the same error what you mentioned can i know how you made it