When to Use Flow Instead of Validation Rules

When to Use Flow Instead of Validation Rules

In the Winter '24 release, Salesforce introduced a new flow element called Custom Error. This feature allows you to display error messages directly within record-triggered flows. Previously, a common workaround involved using a checkbox field in combination with a validation rule to trigger error messages. However, this approach required creating a separate checkbox field and validation rule for each unique error message. Additionally, it only worked in before-save record-triggered flows and didn’t support before-delete scenarios. The Custom Error element in flows can now cover almost everything Validation Rules can do. So, when should you use Validation Rules instead of Flow, or vice versa?

Choosing Between Validation Rules and Flow

Since the Custom Error element in Flows can now handle nearly everything Validation Rules can, it's important to understand when to use each. Before comparing the two, it's worth noting that Custom Error is not meant to replace Validation Rules. Validation Rules are not going away and continue to play a key role in our implementations.

  • Complex Validations: This is where the main difference lies. The Custom Error element is part of Flow, which gives you much more control over the logic. You can use Flow elements to fetch related or even unrelated records and build validations based on that data. So, for complex validation requirements, Flow is the way to go.
Using Flow to Build Validation Rules
Custom Error Element to Block Deleting Records
  • Versioning: Validation Rules don’t support versioning, so once you make changes, the previous version is lost. Flows, on the other hand, do support versioning. This allows you to activate a previous version of your validation logic whenever needed.
  • Dynamic Error Messages: Validation Rules use hardcoded error messages. However, with Flow, you can use Flow resources to create dynamic, context-specific error messages.
Display Dynamic Error Messages

Should You Stop Using Validation Rules?

These are all great reasons to choose Flow over Validation Rules. So, should you always go with Flow and stop using Validation Rules? I think the answer is no, because there are some solid reasons to prefer Validation Rules too.

Validation Rules have a dedicated section with a clear view in the Object Manager, making it easy to manage them in one place. Although Flows can handle validations as well, it’s often better to use a Validation Rule for simple checks. For example, if you want to require a user to enter a value when a specific field changes, a simple Validation Rule can do the job. While these may seem like minor reasons to choose Validation Rules over Flow, there's one important advantage. Field updates from Approval Processes bypass Validation Rules, but they do not bypass Flow-based validations!

For instance, let’s say you have a Validation Rule that blocks changes to the status field. An Approval Process can still update the status without triggering any errors. However, if you build this validation using Flow, the Approval Process will fail because it cannot bypass Flow-based validations.

Approval Process cannot bypass Flow-based validations

Be the first to comment

Leave a Reply

Your email address will not be published.


*