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
john yungkjohn yungk 

Optimistic Locking with Apex DML

Is there a known pattern for implementing optimistic locking from within an Apex class using DML?

Using Martin Fowler's Optimistic Offline Lock pattern as a starting point, it would seem to me that the update command would have be able to support a where clause, but I don't see that as an option with DML.

I might be missing something important as I am admitedly a newbie.

Thanks in advance.
John
pconpcon
I didn't have a chance to really read over the link included, but have you looked at the FOR UPDATE keyword [1] with a SOQL query?  I wonder if that will get you to what you are trying to accomplish.

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