In the recent Winter ’24 release, Salesforce introduced a remarkable feature in flows – Custom Errors. This enhancement is poised to revolutionize error handling within Record-Triggered flows, presenting developers and administrators with heightened control over validation and error management. The capability to seamlessly integrate custom errors directly within flows serves as a pivotal solution, effectively resolving conflicts that may arise between flow processes and validation rules. This feature ensures a harmonious coexistence, providing a robust framework for developers to optimize and fine-tune their Salesforce workflows.
When to use custom errors in flows
Particularly when performing Data Manipulation Language (DML) operations. In the context of a Record-Triggered Flow, the execution of DML operations is a common scenario, such as creating, updating, or deleting records. Previously, when such operations encountered issues, the default error messages were generic and didn’t provide specific guidance to end-users.
For instance, in this scenario a user attempts to update a record, but the update violates certain criteria or triggers a validation rule (explained below). Instead of presenting a generic error that might confuse the user, the Custom Error Messages element allows developers to craft a specific error message. This message can explain the nature of the issue, guiding the user on what went wrong and how to rectify it. In this scenario, the flow tries to update the contact linked with this case but due to a validation rule written on the contact the flow is not able to update the contact.
Validation Rule – There’s a custom field of checkbox type named “legal” in contact, if “legal” is true the contact cannot be Updated.
Now, with the introduction of the Custom Error Messages element, developers have a powerful tool to enhance the user experience during these DML operations. When a Record-Triggered Flow fails, perhaps due to validation rules, workflow rules, or other criteria, developers can strategically deploy custom error messages. These messages serve as a bridge between the technical details of the error and a user-friendly interface.
How custom errors in flows work
Steps to Implement Custom Errors in Record-Triggered Flows
Step 1: Clone the Existing Flow which is causing an error.
Step 2: Adding a Fault Path and Custom Error.
3. In that Path, Add Element and choose “Custom Error”.
4. Add the desired error message in Custom Error. You can Add more than one error message as per your requirements.
5. Save and activate the flow:
Looking ahead, in the event of a runtime failure for the Display Custom Error flow, the specified custom error message crafted within the fault path using the Custom Error element will be presented.
Things to keep in mind.
1. You will still receive the flow error email from Salesforce. If you don’t want to see this error, then you have to utilize this custom error functionality instead of the Validation rule by adding the same criteria as the validation rule in flow.
Deactivate the Validation Rule
Instead of the Validation Rule Use Decision in Flow to Show Error
1. Use the Same condition in the Decision as in Validation Rule.
2. A Custom Error element is designed to accommodate a single record page error message within a flow.
3. For multiple record page error messages in the same flow, it is advisable to employ additional Custom Error elements.
4. Each field can have only one error message, but distinct fields can feature their own unique error messages.
5. Compound fields are not supported within the context of Custom Error elements.
6. In the event of a fault path execution containing a Custom Error element, the change that triggered the flow will be rolled back.
7. The functionality of Custom error messages is aligned with the addError() Id method in Apex.
In summary, the Custom Error Messages element in Record-Triggered Flows enhances the user experience during DML operations. By providing precise and user-friendly error messages, it transforms error-handling into a collaborative and informative process. This improvement fosters confidence in issue resolution, contributing to a more efficient and user-friendly Salesforce environment. As organizations embrace Salesforce, integrating Custom Error Messages becomes a valuable strategy for operational excellence and user satisfaction. Explore this feature to unlock the full potential of Salesforce’s user-centric design.