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
VJayVJay 

Getting alert " caused by: System.DmlException: Update failed. First exception on row 0 with id 0011r00002K8lkuAAB; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 0011r0000****kuAAA: []"

Getting alert like "caused by: System.DmlException: Update failed. First exception on row 0 with id 0011r00002K8lkuAAB; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 1 records: 0011r005556K8lkuDFDF: []
" due to below query in Handler class.

acctList = [SELECT Id,Credit_Blocked_Salesforce__c,Total_SFDC_Blocked_New__c,(Select Id, Amount, Converted_Amount_USD__c, StageName, Account.ParentId from Opportunities),ParentId,Parent.Total_SFDC_Blocked_New__c FROM Account WHERE Id IN: acctIdOpptyListMap.keySet()];

Could you please suggest the way, how we can optimize this query?
PriyaPriya (Salesforce Developers) 

Hi Vjay,

Since I am not aware of the whole implementation of your org, but these below links may help you to understand the error and you will be able to fix it.
https://developer.salesforce.com/forums/?id=9060G000000I2r1QAC

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

If it get solve please mark as Best Answer so that it can help others in the future.

Regards,

Priya Ranjan

 

Suraj Tripathi 47Suraj Tripathi 47
Hi VJay,

Greetings!

When you have multiple jobs running that update an identical set of records, it's suggested to lock the records FOR the UPDATE keyword.  it'll make sure that the record is locked and no alternative job will update identical records at that time in time. The conflicting job can then wait until the protection on the record is free then perform the specified operation. this may avoid conflicts between jobs that area unit running at the same time and can not offer this exception. you'll refer to the below link to find out additional regarding record protection.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_locking_statements.htm

Thank you!

Regards,
Suraj Tripathi