How to Lock records using Apex in Salesforce?

Using UPDATE keyword in SOQL helps us to lock the records from being updating from another request.

Sample Code:

Account [] objAccts = [SELECT Id, Name FROM Account where Country='India' FOR UPDATE];

Note: We can’t use the ORDER BY keywords in any SOQL query that uses locking.

Leave a Reply