[SalesForce] How to avoid validation rule contradicting the process builder

I have a process builder with several flows. I also have a validation rule. Both the validation rule and the process builder are applicable for one and the same custom object. It is possible the custom object to pass though one of the flows and such flow can change the custom object in a way that the conditions in the validation rule to return true. In that case the flow cannot pass and the following error message is received:

The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 3015E0000008BxE. Flow error messages: An unhandled fault has occurred in this flow
An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help.

What I would like to know in this situation is how to display only the message from the validation rule and to avoid the above error?

Best Answer

Validation rules apply any time a record is altered, whether that alteration takes place in Process Builder, the user interface, or the API. You can't intercept the validation rule's message and allow the update to complete successfully.

In a Process Builder or Flow context, one tactic you can use to allow an un-validated change to go through if and only if it's made via a specific automation is to build a check into your rule for a hidden field (not shown on any page layout, or hidden from users via FLS).

Say we have a Checkbox field Process_Builder_Update__c. Set this to true prior to making your updates. Then, in your validation rule, add a check for this field so that the rule does not evaluate to true when the field is set:

AND(NOT(Process_Builder_Update__c), EXISTING_VALIDATION_RULE)

Then, the validation rule won't go off when your process makes its updates, because it sets Process_Builder_Update__c, but it will still be in effect when your users make changes.

You'll also want to un-set the flag once you're finished, so that users can't bypass the validation rule with the flag still set. Your flow should finish by setting the field back to false.

This won't work if your flow leaves your records in an un-validatable state (where any change will fail the validation rule), because unsetting the field will fail. However, you really won't want to leave your records like that anyway, as it means any user update will fail.

Related Topic