Validation Rules in Flow

How to Create Validation Rules in Salesforce Using Flows

Introduction

Salesforce introduced a new way of creating validation rules using flows a few months ago. This blog post will show you how to create a validation rule flow to prevent users from moving an opportunity to the "Use Case Defined" stage without completing the "Terms in Months" field.

Prerequisites

  • Salesforce org with the "Flow Builder" permission

  • Opportunity object with a "Terms in Months" field and a "Stage Name" field

Step-by-Step Guide

  1. Create a new flow from the Flow Builder.

  2. Select the "Record-Triggered Flow" template.

  3. Set the following flow properties:

    • Flow Name: Validation Rule Test

    • API Name: Validation_Rule_Test

    • Trigger: Record is updated or created

    • Object: Opportunity

  4. Keep the entry conditions wide for simplicity.

  5. Rename the flow to "Validation Rule Test".

  6. Decide if you want one validation per flow record or if you want to use one flow that combines all the validation rules.

  7. Create a validation rule for the specific scenario:

    • Criteria: Stage Name is changed

    • Condition: Terms in Months is null

    • Stage Name is equal to "Use Case Defined"

  8. Save the validation rule.

  9. When the conditions are met, include a "Custom Error" element in the flow.

  10. Configure the custom error message:

    • Label: Custom Error Message

    • Display Type: In a window

    • Message: Please add Terms in Months to move into the Use Case Defined stage.

  11. Activate the flow.

Benefits of Validation Rule Flows

There are two clear benefits of having validation rules as flows:

  1. Validation rules in a flow can be executed first before every other flow, which prevents users from seeing confusing error messages.

  2. You can have one flow that aggregates all the other validation rules on an object, making it easier to manage and maintain validation rules.

Conclusion

Validation rule flows are a powerful tool that can be used to improve the user experience and enforce data integrity in Salesforce. By following the steps in this blog post, you can easily create validation rule flows to meet your specific business needs.

Last updated

Was this helpful?