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
Andrew Slutzky 2Andrew Slutzky 2 

Is it possible to LOCK ROWS via Workflow Rules, Flows or Process Builders?

Hello Developer Support,

QUESTION:
Can you tell me how to remedy this error?

CONTEXT:
It appears this Flow is generating an error, which I believe means multiple processes are trying to edit the same record at the same time. It appears this UNABLE_TO_LOCK_ROW is the issue and can be remedied by locking the records using the FOR UPDATE keyword. Not sure how to do that...

I don't have experience with Apex code; thus, I would like to stay away from it. Looks like 124 leads were not able to be updated because multiple edits were happening at the same time on the same records.

ARTICLE:
https://developer.salesforce.com/forums/?id=9060G000000I2r1QAC

ERROR MESSAGE:
Error element Update_Person_Score (FlowRecordUpdate).
The flow tried to update these records: null. This error occurred: UNABLE_TO_LOCK_ROW: unable to obtain exclusive access to this record or 124 records: 00Q3Z00000lPnucUAC,00Q3Z00000lPnmKUAS,00Q3Z00000lPnpmUAC,00Q3Z00000lPnmJUAS,00Q3Z00000lPnplUAC,00Q3Z00000lPnmdUAC,00Q3Z00000lPnprUAC,00Q3Z00000lPnmOUAS,00Q3Z00000lPnpnUAC,00Q3Z00000lPnmjUAC,00Q3Z00000lPnq6UAC,00Q3Z00000lPnmiUAC,00Q3Z00000lPnq1UAC,00Q3Z00000lPnmxUAC,00Q3Z00000lPnqBUAS,00Q3Z00000lPnmnUAC,00Q3Z00000lPnq7UAC,00Q3Z00000lPnmEUAS,00Q3Z00000lPnm9UAC,00Q3Z00000lPnpkUAC,00Q3Z00000lPnoPUAS,00Q3Z00000lPnrAUAS,00Q3Z00000lPnoGUAS,00Q3Z00000lPnqqUAC,00Q3Z00000lPnvBUAS,00Q3Z00000lPnoZUAS,00Q3Z00000lPnrOUAS,00Q3Z00000lPnoUUAS,00Q3Z00000lPnrJUAS,00Q3Z00000lPnofUAC,00Q3Z00000lPnr

All the best,
Andrew Slutzky
Raj VakatiRaj Vakati
Short answer is no 


ROW_LOCK issue is very common if you have multiple users updating the record at the same time .Or say a batch job is running and is updating a record and same record another trigger or code snippet (usually a future method) is updating.
 
Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];


Using FOR UPDATE keyword helps to achieve a lock a client end to prevent this locking issues .
Here is a small article on sharing model to avoid this granular locking

https://help.salesforce.com/apex/HTViewSolution?urlname=How-can-I-avoid-getting-lock-errors-in-my-organization-1327109108393&language=en_US

http://blogs.developerforce.com/engineering/2013/01/reducing-lock-contention-by-avoiding-account-data-skews.html

Also read on data skews which may be another cause .