We have a requirement to implement the read lock on record such that no other transaction can read that record until the first transaction is completed or committed and other transaction have to wait until the first transaction is completed. Is this possible in Salesforce?
1 Answer
The FOR UPDATE keywords allow you to query records only if they are not already locked, as covered but the second "Locking Consideration" in the documentation.
The important points from these considerations here are:
Other clients can still query the same records while they’re locked.
and:
If you attempt to lock a record currently locked by another client, your process waits a maximum of 10 seconds for the lock to be released before acquiring a new lock.
So as long as both clients are using FOR UPDATE
in their queries you effectively get read locking. It is only when clients are using a mix of with and without FOR UPDATE
that you don't get a read lock.
FOR UPDATE
keywords.