How to Lock records using Apex in Salesforce?

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

Sample Code:

List<Contact> listCon = [SELECT Id, FirstName FROM Contact WHERE FirstName LIKE '%test%' FOR UPDATE];

for(Contact con: listCon) {
    .....................
    .....................
}

Cheers!!!

No comments:

Post a Comment