function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sheila srivatsavsheila srivatsav 

how to lock & unlock a record in sfdc

I need to know how to lock and unlock a record in sfdc

Please let me know frrom real time perspective what other different techniques in what scenarios it will work.

which is the best preferred?

sheila
 
Best Answer chosen by sheila srivatsav
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Sheila,

You can lock the record by giving

Validation rules -- throwing error message while someone is trying to edit,
Permission Sets -- To assign these permission sets to users,
triggers -- in apex you can lock() and unlock() records (Approval.lock(accts, false);) functions,
Approval Process -- to lock records.

Please refer the below links this shows the entire details for locking the record:

https://success.salesforce.com/answers?id=9063A000000iTpEQAU

https://sfdcfanboy.com/2017/04/26/7-ways-to-lock-a-record-in-salesforce/

Thanks
Hope this will be useful.

All Answers

gayathri alaparthigayathri alaparthi
There are multiple ways for locking a record.
  • Validation rules. Though this wont work in all cases as you might have to do ISCHANGED on all fields.
  • triggers.
  • Workflows and record types
  • Approval process Lock and Unlock methods.
  • using FOR UPDATE in SOQL for retriving records to update.
  • OOB Approval process record lock options.
If using for bulk updates FOR Update is better option. Watch out for deadlock situations. 
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Sheila,

You can lock the record by giving

Validation rules -- throwing error message while someone is trying to edit,
Permission Sets -- To assign these permission sets to users,
triggers -- in apex you can lock() and unlock() records (Approval.lock(accts, false);) functions,
Approval Process -- to lock records.

Please refer the below links this shows the entire details for locking the record:

https://success.salesforce.com/answers?id=9063A000000iTpEQAU

https://sfdcfanboy.com/2017/04/26/7-ways-to-lock-a-record-in-salesforce/

Thanks
Hope this will be useful.
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Sheila,
You may get help from the links provided below for locking the record in Salesforce:-
  
http://www.asagarwal.com/how-to-lock-records-in-salesforce/

https://sfdcfanboy.com/2017/04/26/7-ways-to-lock-a-record-in-salesforce/

Please mark this as Best Answer if you find this solution helpful.

Thank You
Ajay Dubedi
 
Buck DukhBuck Dukh
Thanks a lot for the help (http://brightons-locksmiths.co.uk/)regarding this issue.