0
List<Account> acctList = [select Id,billingcountry, shippingcountry from Account where Subsidiary__c = 'VTI China' and billingcountry = null ];

for(Account a : acctList){
    a.billingcountry = 'CN';
}

update acctList;

This is a bit awkward, I've generated a list and do the batch update, but there is still an error message says:

Line: 7, Column: 1 System.DmlException: Update failed. First exception on row 0 with id 0010y00001ZveCfAAJ; first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record or 200 records: 0010y00001ZveCfAAJ,001C000001F4HeuIAF,...

Can anyone help to understand it? Thanks.

2

1 Answer 1

0

It means some other user/process (batch job, asynchronous process etc)is trying to update a record in the acctList and is currently in locked from being updated. Or it could be possible, there are too many children records for account (in M-D relationship) and a child record is currently being updated by some other process/user , resulting in parent record being locked. You can use FOR UPDATE to achieve the locking such as Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];

Refer the links- https://help.salesforce.com/articleView?type=1&mode=1&id=000338933

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

1
  • Manish, thanks for the suggestion. Actually, I've also tried FOR UPDATE in the query but it pops up the same exception. I just limited the query scope and then everything is fine.
    – Jet Cai
    Apr 23, 2020 at 3:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .