How to Lock or Unlock a Record Using Apex In Salesforce?

How to Lock or Unlock a Record Using Apex In Salesforce?
In this blog, you will learn how you can lock or unlock a record using apex in salesforce.

Follow below simple steps

  • Go to Setup
  • Search for Process Automation Settings
  • Enable record locking and unlocking in Apex checkbox and Save

  • Go to Setup
  • Open Developer Console
  • Go To Debug menu
  • Select Open Execute Anonymous Window from dropdown

String recordId ='Paste Record Id Here';
System.debug('1. Is Record Locked ? == > ' + Approval.isLocked(recordId));

Approval.lock(recordId);
System.debug('2. Is Record Locked ? == > ' + Approval.isLocked(recordId));

Approval.unlock(recordId);
System.debug('3. Is Record Locked ? == > ' + Approval.isLocked(recordId));

  • Click on Execute


Follow Us

Posted By : Sudeer Kamat Date :

view_module Related

label Labels

Comments 0