BUSINESS CHALLENGE
We might have to throw errors to the user when a record is being created or updated or deleted based on the requirement.
Previously errors can only be thrown in apex and the developers had to work on it.
Salesforce’s Winter ‘24 release will be introducing an exciting new element called “custom error” in flows. Admins can use this feature to add custom error messages in the flow process based on the user input. In this Blog we explain a case where a custom error can be thrown in the flow using this custom error element.
We will be throwing a custom error to the user whenever a second opportunity with the same name for an account is being created or updated.
STEPS TO ACHIEVE THE REQUIREMENT
CREATE RECORD TRIGGERED FLOW
- From the Quick find search and select Flows → Click New Flow.
- Select Record Triggered flow → Click Create.
- By default the layout is set to Auto Layout.
- Select Object as Opportunity
- Configure Trigger → A record is Created or Updated.
- In condition Requirements, No conditions to be added.
- Optimize the flow for → Select Fast Field Updates.
- Select (+) icon → Select Get Records Element.
- Select Object as Opportunity Object.
- Choose All Conditions Are Met (AND) as the condition requirement
1. Opportunity Name Equals Record >Name
2. Account Id Equals Record>Account Id
- Select All Records option in How Many Records to Store.
- Since we are not performing any operation on any of the Opportunity fields, select the option Choose fields and let Salesforce do the rest so that we don’t have to pull all fields except Id.
- Click Done.
- Click the New Resource button on the left side of the canvas under the
- Enter API Name as recordcount.
- Select Data Type as Number, decimal places as 2.
- Click Done.
- Below the Get Records element add an Assignment element and enter the label as Count Opportunities.
- Add the condition requirement as AND,
recordcount as resource, Equals as operator and Count as value.
- Click Done.
- After the Assignment element add a Decision element.
- Enter the label as Check Count.
- Enter Outcome Detail label as Records found.
- In that Decision Element, add the following condition
recordcount > 0
- Add a Custom error element( this custom error element helps us to display an error when a user enters the same name for a second opportunity for an account.
- Choose the type of error you want, enter the error message that you want to display.
- Click Save & Activate.
WRAPPING IT UP
In this blog we have covered how to display custom error messages to the user using a custom error element in a record triggered flow.
Leave a Comment