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.
Formula returns TRUE for invalid data
Screen Flow Validation
Set via Validate Input on a field component in Flow Builder.
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
Tips voor gebruik:
- Gebruik API-namen van velden (bijv.
Account.Name,Custom_Field__c) - Voor datums: typ
TODAYvoor vandaag, of2025-12-31voor 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
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).
Open Validation Rules
Click Validation Rules in the object menu. You'll see an overview of existing rules.
Create a new rule
Click New to add a new validation rule.
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
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:
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
Open the relevant Flow in the Flow Builder
Select the screen containing the field you want to validate
Click on the field component to view its properties
Find the section Validate Input
Paste the generated formula in the formula field
Fill in at Error Message the text the user sees
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.
ISPICKVAL(picklist_field, text)
Checks if a picklist field has a certain value. Use this instead of comparing the field directly to text.
INCLUDES(multipicklist_field, text)
For multi-select picklists: checks if a certain option 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.
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.
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.
