Using Flow to Lock and Unlock Records

Using Flow to Lock and Unlock Records

In some situations, you may want to prevent further edits to a record. Although it is possible to implement this using validation rules, wouldn't it be nice to have the record locking functionality of the approval process? Well, good news! Salesforce introduced a new standard action to lock or unlock records in the Summer '24 release. Using this new action, it is possible to lock records and specify who can edit the record while it’s locked. Here is how to use this new core action.

Action to Lock Records

Input Values

After adding a new action to your Flow canvas and choosing the Lock Record action, you need to set the input values. This action has only 3 input values, which makes it easy to configure.

  • Action: It specifies the action to perform on the record. Valid values are "Lock" or "Unlock". It doesn't have a selection, which means that you need to type it. You must enter a value.
  • Record ID: The ID of the record that you want to lock or unlock. You must enter a value.
  • Allowed ID: The ID of a user, group, queue, or user role that represents who can edit the record while it's locked. It is an optional input parameter.

If you specify a user role for the "Allowed ID" parameter, users must hold a role equal to or above the specified role in the hierarchy to edit the locked record.

How to Use the Action

Let's say that we want to lock the Case records when their status becomes Closed. In order to build this automation, we need to use a record-triggered flow. As you can see, you just need to use the standard Lock Record action.

Flow to Lock Case Record

After the flow runs and locks the record, other users will get this error when trying to edit the record.

Record Locked Error

Once the record is locked, a system administrator, the user who locked the record, or a designated allowed user can unlock the record. Any other user attempting to unlock the record will encounter an error with the INSUFFICIENT_ACCESS_OR_READ_ONLY error code.

At this moment, the Case record is locked. So, what happens if we trigger our flow again? It will try to lock the record but it is already locked.

Flow Failure

As you can see, the flow fails! To avoid this flow failure, you may want to first check if the record is locked or not.

How to Check the Lock Status

There is no standard action to get the lock status and it is not a simple Get that you can perform. However, you can use this custom invocable action in order to check if the record is locked or not.

Here are the steps to use the action.

1- Install the component using the installation links below.

2- Add a new action to your flow and search for "Check Record Lock Status", this is the name of the component that you installed.

3- As an input, provide the ID of the record that you want to check its lock status.

Check Record Lock Status

4- Output of this action is a boolean and it returns true if the record is locked. You can use a Decision element to check if the record is locked.

Decision to Check Lock Status

If the record is not locked, then you can use the standard Lock Record action to lock it.

Using Flow to Lock and Unlock Records

Installation Links

Use this link to install in production or developer edition environments.

Use this link to install in sandbox environments.

Be the first to comment

Leave a Reply

Your email address will not be published.


*