Validation Rules in Salesforce

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. 

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.