subscribe our youtube channel popup

Validation Rules in Salesforce [With Examples]

Validation rules in Salesforce are essential for ensuring data integrity and consistency within your organization. They help enforce specific criteria for your data fields and can prevent users from saving records that don’t meet pre-defined conditions. In this article, I will discuss the Top 5 validation rules that you should create as an admin in your client’s Salesforce org. But before that, let’s have a quick summary of validation rules like Validation Rules in Salesforce and when to use validation rules.

What are Validation Rules in Salesforce?

Validation rules are used to enforce data quality and consistency by validating data entered by users before saving it to the database. These rules are expressions or formulas which check the data and determine whether it meets specified criteria. 

How to Create Validation Rules? 

Follow the below step to create validation rules in Salesforce

  1. Go to the Object manager
  2. Select the object on which you want to create a validation rule.
  3. Then click on Validation Rules. Then Click on the New button.
  4. Then, type your validation rules.
Aggregating & Validating Data | Formula field | Roll-up Summaries | Duplicate Rules | EP-4

Top 5 Validation Rules Examples

Here are some important validation rules which you can configure in your org:

1. The account number is Numeric 

There might be a scenario where you want your user to enter only numeric values in the Account Number field of Account Object. You can configure the below validation rule for the same.

OR(
ISBLANK(AccountNumber),
NOT(ISNUMBER(AccountNumber))
)

Below is the screenshot of the validation rule.

Now if you try to enter text value in the Account Number field it will give an error message as you can see below.

2. Annual Revenue Range

There could be scenarios where you don’t deal with accounts having annual revenue greater than a specific number. You can enforce this using the below rule.

OR(
AnnualRevenue < 0,
AnnualRevenue > 1000000
)

Below is the screenshot of the rule.

Now if you try to enter annual revenue greater than 1 million then you will get an error.

3. Close Date Must Be a Future Date

Sales reps often select past dates in an opportunity closed date field and you want to restrict them. This can be achieved by the below validation rule.

CloseDate< today()

Below is the screenshot of the rule.

Below is the error you will get when you enter the past date in the opportunity close date field.

4. Prevent Open Cases from Being Reset to New

Sometimes service agents change the status of open cases to New you want to restrict. These can be achieved by below validation rules.

AND(
ISCHANGED( Status ),
NOT(ISPICKVAL(PRIORVALUE( Status ), "New")),
ISPICKVAL( Status, "New")
)

Below is the screenshot of the configured validation rule.

And below is the screenshot of the error message which you will get while trying to set the status of open cases to new.

5. Blank Email or Mobile

There can be scenarios where you want at least one communication detail to be available on contact record like email or mobile number. These can be configured by the below validation rule.

AND(
 ISBLANK( Email ) , 
 ISBLANK( MobilePhone ) 
)

Below is the screenshot of the configured rule.

Below is the error you will get when you leave email or mobile empty.

So these are some common rules which you should create in salesforce org to enforce data quality. If you have any rule in mind then please post in the comment below so we all can learn.

Validation Rules Best Practices

  • Keep your validation rules as simple as possible to avoid confusion.
  • Test your rules thoroughly to ensure they work as intended and do not interfere with legitimate processes.
  • Use descriptive error messages to guide users on how to correct their entries.

Summary

By effectively using validation rules, you can maintain a high level of data quality and adherence to your organization’s processes within Salesforce.

Shubham Lashkan
Shubham Lashkan
Articles: 10

One comment

  1. Please don’t use that close date validation, it will block all future updates on the opportunity, no matter what is the good reason you might want to update it

Leave a Reply

Your email address will not be published. Required fields are marked *