+ 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.
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