AUTOMATION Β· 15 min lezen

Validation Rules in Salesforce

Enforcing data quality with smart validation.

What is a validation rule?

A validation rule is a condition (formula) that checks whether entered data meets certain criteria. When that formula returns TRUE, the input is considered invalid and Salesforce prevents the record from being saved.

In other words: the validation rule verifies the entered data and blocks saving if it doesn't meet the standard. Users then see an error message explaining which field values are invalid.

πŸ’‘ How does it work in practice?

When a user saves a new record or updates an existing one, all active validation rules for that object are checked. If all data is valid (none of the rules return TRUE), the save proceeds normally.

But if one or more validation rules return TRUE (meaning they find invalid input), then:

  • The save is cancelled and the record remains unchanged
  • The user immediately sees an error message
  • The user must correct the input and save again

The two components of a validation rule

A validation rule consists of two important components:

1. The Formula

The formula describes the condition that should not be true. For example: "Completion date must not be in the future". If this condition is true anyway, the rule blocks the save.

2. The Error Message

The text the user sees when the rule triggers. For example: "Completion date cannot be in the future." You can choose whether this appears at the top of the page or next to a specific field.

⚠️ Note

Validation rules are always active, regardless of whether a field is on the page layout or not. A rule that checks a hidden field will still block input if the condition is met.

Object validation rules vs. validation in Flows

Salesforce offers two ways to validate data: at the object level and in Screen Flows. While the goal is similar, the implementation differs.

Object Validation Rule

Created via Setup β†’ Object Manager. Evaluates record data after clicking Save.

Checks on save (UI, API, import)
Applies to new and existing records
Valid for entire organization
TRUE=Error (block)

Formula returns TRUE for invalid data

Screen Flow Validation

Set via Validate Input on a field component in Flow Builder.

Checks immediately while filling in
Direct visual feedback for user
Only active within the specific Flow
TRUE=Valid (allow)

Formula returns TRUE for valid data

The key difference: reversed logic!

For objects you write the formula as "when is the input invalid?" (TRUE causes error). For flows you write the formula as "when is the input valid?" (FALSE causes error).

βœ… Our tool does this automatically

In the interactive generator below, you can indicate whether you want to generate a rule for an object or for a flow. The tool automatically reverses the logic for flow validations, so you can use the formula directly.

Interactive Validation Rule Generator

Use the tool below to build a validation rule formula step by step. This is especially useful if you don't write formulas regularly and want to be sure the syntax is correct.

Validatieregel Generator

Conditie 1
Conditie 2
Conditie 3

Tips voor gebruik:

  • Gebruik API-namen van velden (bijv. Account.Name, Custom_Field__c)
  • Voor datums: typ TODAY voor vandaag, of 2025-12-31 voor een vaste datum
  • Decimalen met punt schrijven (bijv. 3.5)
  • Vergelijken met ander veld? Vul de API-naam in als waarde

Applying the generated validation rule in Salesforce

As an object validation rule (when saving records)

If you've created a formula for an object with the tool, add it to Salesforce as follows:

Step-by-step walkthrough

1
Go to Setup

Navigate to Object Manager and select the object where you want to create the rule (for example Account, Contact or a custom object).

2
Open Validation Rules

Click Validation Rules in the object menu. You'll see an overview of existing rules.

3
Create a new rule

Click New to add a new validation rule.

4
Fill in the fields

Configure the rule:

  • Rule Name – A clear name (e.g. "Account_Number_8_Characters")
  • Active – Check to make the rule immediately active
  • Description – Briefly describe what the rule does
  • Error Condition Formula – Paste the generated formula here
  • Error Message – The text the user sees
  • Error Location – At the top of the page or next to a specific field
5
Check and save

Click Check Syntax to validate the formula, then save with Save.

πŸ”Ž Practical example

Suppose you create a rule on Opportunity with the formula:

AND(ISPICKVAL(StageName, "Closed Won"), ISBLANK(Project_Start_Date__c))

This rule requires a custom field "Project Start Date" to be filled in once the opportunity reaches the "Closed Won" stage. If a user tries to save an Opportunity as Closed Won without a start date, the error message appears.

As validation in a Flow screen (Screen Flow)

When you've generated a formula for Flow, you can use it in a Screen Flow:

Flow Builder Steps

1

Open the relevant Flow in the Flow Builder

2

Select the screen containing the field you want to validate

3

Click on the field component to view its properties

4

Find the section Validate Input

5

Paste the generated formula in the formula field

6

Fill in at Error Message the text the user sees

7

Save and test the flow

Common formula functions

Salesforce offers many functions for formulas. Here are the most commonly used for validation rules:

ISBLANK(field)

Checks if a field is empty (contains no value). Use this instead of comparing to an empty string.

ISBLANK(Email) β†’ TRUE if Email is empty

ISPICKVAL(picklist_field, text)

Checks if a picklist field has a certain value. Use this instead of comparing the field directly to text.

ISPICKVAL(Status__c, "Active") β†’ TRUE if Status__c = "Active"

INCLUDES(multipicklist_field, text)

For multi-select picklists: checks if a certain option is selected.

INCLUDES(Interests__c, "Sports") β†’ TRUE if "Sports" is selected

AND() and OR()

Combine multiple conditions. Use AND if all conditions must be true, or OR if one of multiple conditions is sufficient.

AND(ISBLANK(Phone), ISBLANK(Email)) β†’ TRUE if both are empty
OR(ISBLANK(Phone), ISBLANK(Email)) β†’ TRUE if either is empty

REGEX(text, regex_pattern)

Checks if a text field matches a certain pattern. Powerful for format validations like postal codes or email addresses.

NOT(REGEX(PostalCode__c, "[0-9]{4}[A-Z]{2}")) β†’ Error if postal code doesn't have NL format

Best practices for validation rules

βœ… Write clear error messages

The end user sees the error message, not the formula. Avoid jargon and explain what's wrong and how to fix it. For example: "Date cannot be in the future" is clearer than "Invalid date".

βœ… Test thoroughly

Try different scenarios – both data that should be accepted and data that should be blocked. A poorly designed validation rule can prevent users from saving valid data too.

βœ… Introduce gradually

It's not advisable to deploy many new validation rules to production at once. Better to do it step by step, so you can handle any unexpected effects. Inform users about new rules.

βœ… Document your rules

Give each rule a clear name and description in Salesforce. This makes it easier for you or fellow admins to understand the purpose later.

⚠️ Consider integrations and imports

Validation rules always run when saving a record, regardless of who or which method (UI, data load, API) makes the change. Keep this in mind with integrations or imports: rules will also trigger then and data must meet the specified conditions.

Common validation scenarios

Required fields by status

Project start date required when Opportunity moves to "Closed Won".

Date validation

End date must not be before start date, or close date must not be in the future.

Format checking

Postal code must be 4 digits + 2 letters, or phone number must start with +31.

Value range

Discount percentage must be between 0 and 30%, or amount must be at least €100.

Contact info required

At least phone or email must be filled in on a Contact record.

Picklist dependency

Reason field required when status is set to "Rejected".

Conclusion

Validation rules are a powerful tool for ensuring data quality in Salesforce. By validating smartly, you prevent errors at the source and ensure consistent data throughout your organization.

With our interactive generator, you can quickly build the right formula without having to memorize exact syntax. Start with simple rules and build out gradually as you gain more experience.

Further learning

Want to learn more about automation in Salesforce? Also check out our articles on Salesforce Flow and the Order of Execution to understand when validation rules run.

Need help setting up validation rules?

We help you ensure the right data quality with smart validations and clear error messages.