Activity Forums Salesforce® Discussions How can we lock record using SOQL so that it cannot be modified by other user in salesforce?

  • Manpreet

    Member
    April 11, 2017 at 4:52 am

    Hi saurabh,

    we will need “FOR UPDATE” clause of SOQL.
    Sample :
    Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];

    Thanks.

  • Avnish Yadav

    Member
    September 30, 2018 at 12:30 am

    In Apex, you can use FOR UPDATE to lock sObject records while they’re being updated in order to prevent race conditions and other thread safety problems.
    While an sObject record is locked, no other client or user is allowed to make updates either through code or the Salesforce user interface.

    For example, the following statement, in addition to querying for two accounts, also locks the accounts that are returned:

    Account [] accts = [SELECT Id FROM Account LIMIT 2 FOR UPDATE];

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos