• #20119
    Salesforce | Saurabh Saurabh #132
    Forcetalks

    How can you lock record using SOQL in Salesforce so that it cannot be modified by other user?

    How can you lock record using SOQL so that it cannot be modified by other user.

     

    #20138
    Salesforce | Suraj Suraj #163
    Forcetalks

    Hi Saurabh,

    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];

    #41267
    Forcetalks

    We will need “FOR UPDATE” clause of SOQL.

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

    Thanks.

Viewing 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?