I am trying to create a reusable method which retries DML whenever record lock is detected.
However, I noticed that even if you set database.update( collection, **false**)
and there is at least one locked record in the collection, each of the records will get marked as locked.
To replicate:
trigger LeadTrigger on Lead (before update) {
lead[] l = new lead[]{};
if ( trigger.new[0].email != '[email protected]' && true )
for (integer i = 0; i < 10000000; i++)
l.add (new lead(email='a'+i+'@as.com'));
}
Modify any lead record to kick into very long process and at the same time execute anonymously:
lead[] la = [select id, email from lead ];
for (lead l: la)
l.email = '[email protected]';
system.debug( database.update( la, false ) );
This returns
USER_DEBUG [12]|DEBUG|(Database.SaveResult[getErrors=(Database.Error[getFields=();getMessage=unable to obtain exclusive access to this record or 3 records: 00Q28000001PrsEewS,00Q28000001PrszzAS,00Q28000001PrsGeaS;getStatusCode=UNABLE_TO_LOCK_ROW;]);getId=null;isSuccess=false;], Database.SaveResult[getErrors=(Database.Error[getFields=();getMessage=unable to obtain exclusive access to this record or 3 records: 00Q28000001PrsEewS,00Q28000001PrszzAS,00Q28000001PrsGeaS;getStatusCode=UNABLE_TO_LOCK_ROW;]);getId=null;isSuccess=false;], Database.SaveResult[getErrors=(Database.Error[getFields=();getMessage=unable to obtain exclusive access to this record or 3 records: {...}
My expectation is that all but that one record would get updated.