Salesforce Flow error messages are something that every user in the ecosystem faces. Traditionally, when you run into a flow error when trying to save a record, you are presented with a cryptic error message that doesn’t always make sense regarding the issue. If you’re a regular user at your company, you will probably forward a screenshot of this error and send it to your internal Salesforce Admin so they can investigate and let you know what is wrong.
With error messages, there were limited options for creating these when editing a record in Salesforce. Options available to us were a validation rule or writing code and doing it through Apex. With the Winter 24 release, the ability to create a custom error message in a record-triggered flow was made instead of cryptic messages. You can create specific messages so the user knows the issue, correct the error, and get on with their day.
The scenario we are going to use:
A sales rep wants to close out an Account in the database and clicks the Close Account checkbox that the company admin created. When this checkbox is checked and the Record is saved, automation will delete the Account. You cannot delete the Record if any Closed Won opportunities are associated with this Account. In this case, we will base things on no Closed Won Opportunities.
Steps on how to use this feature:
Create a Close Account Checkbox Field
- Go to Setup and click on the Object Manager tab
- Click on Account
- Click Fields & Relationships
- Click New
- Click Checkbox
- Label the field Close Account and leave Unchecked for Default Value.
Click Next twice and then click Save.
Create Flow to Delete Account
- In the Setup type flow in the Quick Find box
- Click on Flow
- Click New Flow and click on Record–Triggered Flow
- Click Create
- In the Object, choose Account
- Choose “A record is updated” on the Configure Trigger section
- Choose “All Conditions Are Met (AND) in the Condition Requirements.”
- In the field, select the field that you created Close_Account__c
- Operator set to Equals
- Value True
- Click “+” to add element
- Scroll down and click on Delete Record
- Label your element, Delete Account
- Choose Specify conditions in How to Find Records to Delete
- In the Object, select Account
- In the Filter Account Record section. In the field, select Id
- Operator set to Equals
- Value is Record>Account ID
- Save and Activate your flow
Testing
- Before you test, ensure at least one open case record associated with the Account you are trying to delete with automation.
- Go to your Account record.
- Click Edit
- Check the Close Account checkbox and save
- You will notice that you get the standard long error message that Salesforce typically gives you. See image below:
This lengthy message says that there is an open case associated with the Account that you are trying to delete, which is why you cannot delete this Record through the automation you just built.
Return to the DeleteAccount automation you recently built and add a custom Error Message.
- Open the Delete Account flow you created
- Click on the Delete Record element
- Click Add Fault Path
- Click “+” under Fault
- Type “custom” and select Custom Error
- Select where you want your error message to show
- Paste into the error message body: Account: {!$Record.Name} has open cases. Please ensure all cases are closed out before closing out of the Account.
- Click Save and Activate
Retesting Automation
- Go to your Account record.
- Click Edit
- Check the Close Account checkbox and save
- You will notice that the standard long error message is no longer there and has been replaced with the message you updated your flow.
See the image below.
Let XTIVIA help you with your Salesforce Custom Error Messages with our certified Salesforce experts. Don’t forget to ask us about our Salesforce Admin On-Demand service– contact us today!