Is there a way to re-lock a record immediately after it has been approved via an Approval Process (in the same transaction)? It seems like a simple thing to do via a Trigger but I have an After Update (and Before Update for good measure) Trigger that tries to lock the record using Approval.lock
but it fails without throwing an error. Subsequent updates to the record will lock it, showing that the Trigger criteria are correct.
Notes:
Despite Unlock the record for editing
being the first Action in the "Final Approval Actions" list of the Approval Process, the record shows as locked
when looked at via Approval.isLocked()
before my re-locking code runs.
I would prefer not to use a separate Read-Only layout to get around this issue.
I would prefer not to use setup a time-based Workflow to touch the record shortly after the record is approved.
Steps performed:
- User submits the record for Approval (record is locked)
- Eligible approver hits the Approve button
- The Final Approval Actions has an Action that unlocks the record along with multiple field updates (one of which changes the Stage Name to a value which should then get the record locked via custom Trigger code)
- Field updates from the Final Approval Actions cause the Trigger to run - it finds that the Stage Name has changed to a specific value to it tries to lock the record
- The page then loads up showing that the record is unlocked without it seeming to flipflop between locked and unlocked in the transaction's Field History