SOQL - concurrent reads of rows when FOR UPDATE clause is used

If the lock from the first user gets released within 5 seconds, will the second user get access to the same record even though now the status of the record is 'unavailable'?

I had to answer the same thing for some of my own architecture, and I can definitively say that if your other operation changes the Status__c to no longer equal 'Available', then your locking query will not return that record.

If the lock from the first user gets released within 5 seconds and the record doesn't meet the status search criteria where Status__c ='Available' will SF automatically query for a new record?

I believe you will get an empty query result, but I have not been able to confirm.


We created Case #26144866 with salesforce and below was their response. Just posted it as an additional answer for benefit of others since for Q2, SF Support mentioned it will query and return a new record.

Question 1. If the lock from the first user gets released within 5 seconds, will the second user get access to the same record even though now the status of the record is 'unavailable'?

Answer: No - the query will be re-run and the user will get a new result. The previous record will no longer be a valid result and will not be returned by the query.

Question 2. If the lock from the first user gets released within 5 seconds and the record doesn't meet the status search criteria where Status__c ='Available' will SF automatically query for a new record?

Answer: Yes - for the same reasons stated above. The query will re-run and will return a new result.