Like the before-insert trigger, we can also create a before-insert flow to process record data before it is saved to the database. In this post, we will see how to create a before-insert flow in Salesforce with a step-by-step procedure.
Use Case
The requirement is to convert the Product Code entered by the user to uppercase when a new product is created.
Create "before insert" flow step-by-step
- Go to setup and search for
flow
in the quick find. - Click
New flow
and then selectRecord-Triggered Flow
. -
Select the Object (which is Product here) and select the trigger event
A record is created
like below:
New Record Trigged flow on Product - Now scroll down further on the same page and in the
Set Entry Conditions
section select theFast Field Update
option to run the flows before inserting the record. Like below:
Create record trigged flow with fast field update (before insert) - Additionally, you can select entry conditions for flow, for this example,
I am checking if the "Product Code" field is not empty or null.
Add entry condition to flow. - Now that we have entry conditions for the flow it's time to update the
fields. Because this is a before-save flow, we don't need to use the
"Update Record" action, we just need to set the field values using the
"Assignment" action and Salesforce will automatically save the data.
Remember: It is important to note that we don't use the "Update Record" action in the before-save flow. -
Let us create an assignment operation to convert the "Product Code" field
into Uppercase. But before that, we need a formula resource to convert the
old "Product Code" to upper case because we can't use the formula directly
in the Assignment operation.
Formula - Convert to Uppercase - Let us plug this formula into the assignment operation
Use the formula resource in the assignment - That's all, "before save" i.e. "before insert" flow is ready, it's time to activate and test the flow. Create a new product record with the "Product Code" value populated, and it should be converted to uppercase.
- Once activated properly test flow and migrate to the production org.
When to/not to use before save/fast field update flows?
- You would typically use "before save" flows in Salesforce when you need to execute actions or validations before a record is saved to the database. On the other hand, "fast field update" flows are employed for efficiently updating fields on multiple records in bulk operations.
- Don't use flows when you need to update a related record. Additionally, if the logic you need to execute is more appropriate for post-save processing, such as sending emails or triggering subsequent actions, then a "before save" flow would not be suitable.
No comments :
Post a Comment
Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, email us at rahul@forcetrails.com