Ever run into this frustrating little gem in your Salesforce deployment or Apex tests?

System.NoAccessException: Apex approval lock/unlock API preference not enabled

Yeah, us too. If you’re trying to use Approval.lock(record) or Approval.unlock(record) in Apex, Salesforce needs you to explicitly enable the feature first. Here’s how to do it — with a side of clarity and speed.

Why This Happens

Salesforce, in its infinite wisdom, has made the ability to lock or unlock records via Apex an opt-in setting. That means the feature is off by default in every org — even scratch orgs and sandboxes — unless you explicitly enable it.

So when your code hits:

Approval.lock(myRecord);

…you get slapped with a NoAccessException unless you’ve flipped the correct switch.

How to Fix It

Here’s the step-by-step path to enabling record locking/unlocking in Apex.

If You’re Using Lightning Experience:

  1. Navigate to Setup
  2. Search for and go to:
    Process Automation Settings
  3. Check the box:
    Enable record locking and unlocking in Apex
  4. Click Save

If You’re Using Salesforce Classic:

  1. Go to Setup
  2. Navigate to:
    Create → Workflows and Approvals → Process Automation Settings
  3. Again, check the box:
    Enable record locking and unlocking in Apex
  4. Save and you’re golden.

🔒 Pro Tip: This setting is org-wide. Once it’s enabled, any Apex code using Approval.lock() or Approval.unlock() will work as expected across your org.

Final Thoughts

This is one of those “set it and forget it” settings in Salesforce that can trip up even experienced devs. Now you know how to fix it quickly—and keep your deployment moving forward.

Admin

Recent Comments

No comments to show.