Approval process is an automation tool that lets users approve records in Salesforce. An approval process can have one or more steps. Using the steps, it is possible to request approval from users and define what to do at each step of the process. You can add actions to initial submission, approval steps, final approval, final rejection, or recall. However, there are only four supported actions.
- Email alert: Send an email to a recipient using an email template.
- Task: Create a task record to a specified user.
- Field update: Update a field of the record.
- Outbound message: Send a message to a designated endpoint.
If you are familiar with workflow rules, you can see that these are the same actions that are supported by workflow rules. If you want to perform an action that is not listed here, you can perform it by triggering another automation tool. Since Process Builder and Workflow Rules will be retired in the near future, flow is the best option here. Read this post to learn more about the retirement process of these automation tools.
Even though there is an option to update fields, it is very limited. It doesn't support using values from the process, including the approval or rejection comments. In order to update a field with a value from the process, you have to use a flow. However, how can you trigger a flow from an approval process? Actually, it is simple. You have to update a field and this field update should be the trigger of the flow.
Let's see an example of saving the approval comment to a field on a case record.
Saving the Approval Comment to a Field on Case Record
Add an Approval Action to the Approval Process
Let's assume that there is an approval process for the case object. In order to trigger the flow, you have to add a field update as the approval action of the process. In this example, there is only one step in the process and the goal is to save the approval comment. If you need to do the same for more steps or also for rejection, just add a specific action to trigger the flow.
As you can see, at the end of the approval process, there is a field update to mark a checkbox field on the case record. Make sure that you mark "Re-evaluate Workflow Rules after Field Change".
Create a Record Triggered Flow to Save the Approval Comment
Starting with the Spring '22 release, field changes made by approval processes can run record-triggered flows. Before this release, you had to use a Process Builder in order to trigger your autolaunched flow. Since it is a new feature of the Spring '22 release, pay attention that you are using API version 54 or higher. Read this post to learn more about this change and the other great features of Spring '22 release.
1- Create a record-triggered flow. Select case as the object and enter the checkbox field as the criteria. Make sure that the flow runs on update and only when the record is updated to meet the condition requirements.
Depending on your needs, you can make it an after-save flow by selecting "Actions and Related Records". However, in this example you will just update a field on the same record. So, "Fast Field Updates" is a better option for this example.
2- Add a Get Records element to get the last Process Instance record related to the case. This is the record that stores the approval process information related to the case.
3- Just to make sure, add a Decision element to check if there is a Process Instance record related to the case. Otherwise, there is no reason to continue the flow.
4- Add a Get Records element to get the Process Instance Step related to the Process Instance that you found. This object stores the information of the approval step status related to the approval process. Add another criteria to get the record that has Approved StepStatus. This criteria is needed because the goal is to save the comments that the user wrote while approving. If you want to do it for rejection as well, add a criteria with StepStatus equals to Rejected.
5- Add a Decision element to check if Process Instance Step exists. If not, there is no reason to continue the flow.
6- Add an Update Records element to update the case record. Comments are stored in the Comments field of the Process Instance Step record. If you need more information such as the approver, you can find the user Id in the ActorId field of the Process Instance Step record.
In order to save the date/time and keep the existing value in the field, create a formula.
End of the Flow
This is the end of the flow. Make sure that you activate the flow after saving it. Your flow should look like this.
Since you are triggering a flow, it is possible to perform any kind of actions. You can create, update or delete any record in the system. You can send custom notifications, or post on Chatter, or anything that you need. So it means that, even though the approval process support only four type of actions, it is possible to extend the possibilities using a flow.