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

  • Manpreet

    Member
    May 8, 2017 at 1:00 pm

    Hi saurabh,

    We will need “FOR UPDATE” clause of SOQL.

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

    Thanks.

  • Avnish Yadav

    Member
    September 30, 2018 at 12:29 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

Salesforce Integration Tutorial | Integrate Salesforce with Apps

Video in

This "𝐒𝐚𝐥𝐞𝐬𝐟𝐨𝐫𝐜𝐞 𝐈𝐧𝐭𝐞𝐠𝐫𝐚𝐭𝐢𝐨𝐧 𝐓𝐮𝐭𝐨𝐫𝐢𝐚𝐥" video by Edureka will help you understand what is Salesforce integration in detail. It will also address the various Salesforce integration…