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.
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.
After the flow runs and locks the record, other users will get this error when trying to edit the record.
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.
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.
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.
If the record is not locked, then you can use the standard Lock Record action to lock it.
Installation Links
Use this link to install in production or developer edition environments.
Use this link to install in sandbox environments.
Thanks Yumi for this article !
It seems that Salesforce has pushed this feature a bit early: no picklist to select the action, no custom lock message and no way to know easily that it's already lock.
Thank you for the package, that would be useful.
Hey Yumi, we have been waiting for this for so long, however, upon testing in Sandbox for the Opportunity Object, I'm getting this error and was wondering if you encountered the same on your tests?
We can't save this record because the “AUS: Application Lock Flow” process failed. Give your Salesforce admin these details. Missing required input parameter: action Cannot invoke "String.toLowerCase()" because "apiName" is null Error ID: 1309399855-1165649 (-1613589745)invoke "String.toLowerCase()" because "apiName" is null Error ID: 1309399855-1165649 (-1613589745)
Is this error coming from the standard action? Valid values are "Lock" or "Unlock". Make sure that you are writing exactly like that.
Thanks Yumi, I'll check it out
I have been breaking my brain trying to figure this out. I was starting to type then selecting my components in the flow without realizing I had to just type in the correct value. I am trying to unlock the record, update it, then relock it in my flow.
However, once I did that correctly, I ran into a different error. When I look at the flow details in the error, it appears to be unlocking the record, then when it tries to update the field, it fails because it's trying to update a locked record:
LOCK RECORD: Unlock Record
Inputs:
recordId = {!$Record.Id} (id of record)
action = Unlock
Outputs:
None.
UPDATE RECORDS: Set Email Sent to True
Update the Medical_Inquiry_vod__c record that triggered the flow:
Conditions to update the record
None—Always Update Record
Update the record's fields
'checkbox field' = true
Triggering Medical_Inquiry_vod__c Record Values
[copious record details]
Result
Failed to update the Medical_Inquiry_vod__c record.
It doesn't actually even create the record at all, it's like the process fails and then the record isn't even saved.