Hi, readers hope you are doing good. In this session, we are going to learn what is Validation Rule in Salesforce. A validation rule contains the formula or expression that validate the data and return a boolean value. This boolean value determines whether the user data should save or not.

After completing this tutorial you will be able to understand:

  • What is Validation Rule in Salesforce?
  • How to create Validation Rule in Salesforce?

What you’ll do?

  • Create a Validation Rule on the opportunity object that will ensure Closed Won Opportunity must have the amount greater than 0.

What is Validation Rule?

Data accuracy is the biggest challenge for any application. Every application should perform certain business checks so that wrong data cannot be inserted. Salesforce provides a number of things to ensure that the user is entering correct data that is relevant to your Org.Validation rules are helpful for such scenarios.

A Validation rule in salesforce is a criteria which is used to ensure that the data entered by the user meets the standard you specified.
A Validation rule helps us to improve the quality of your data by ensuring the data meet the business rule and is clean to start with.

A validation rule contains the formula or expression that validate the data and return a boolean value. This boolean value determines whether the user data should save or not. If the expression returns true that means the data entered by the user is incorrect and we can not allow the user to save data. If the expression is false the data is good and a user can save the record. This is why the validation rule is important for your business data.

It is good to include an error message while creating a validation rule to notify users that their changes are not saved.

Steps for Creating a Validation Rule:

  • Goto SetUp>>Customize>>Opportunity(Any Object).
  • From left sidebar click validation rule.
  • Click New.
  • Enter the Name of the rule.
  • In the Error Condition, Formula section defines your criteria to validate the data.
  • To check the formula or expression for error click on Check Syntax.
  • In Error, Message section defines your custom message and position which will appear when user enters wrong data.
  • Finally, Save it.

Example:

Scenario: Now we are going to write validation rule for Opportunity object which fires when Opportunity is saved. This rule validates the Amount is greater than zero for Closed Won Opportunity

  • Goto SetUp>>Customize>>Opportunity.
  • From left sidebar click validation rule.
  • Click New.
  • Enter the Name of the rule i.e. AmountGreaterThanOnClosedWon
  • In the Error Condition, Formula section defines your criteria to validate the data. i.e
ISPICKVAL(StageName, 'Closed Won')&& (Amount<=0 || Amount =null)
  • To check the formula or expression for error click on Check Syntax.
  • In Error, Message section defines your message and position which will appear when a user enters wrong data.
The amount should not be zero for Closed Won Opportunity
  • Finally, Save it.

Here is Your Rule:

Validation Rule

Governor Limit:

In Salesforce Unlimited Edition you can have 500 Active validations rule. In developer Org, you can have 100 Active validation rules.

View More:

Conclusion:

I hope you would love this tutorial. Please don’t hesitate to comment for any technical help. Your feedback and suggestions are always welcome.

Thank You.

Leave a Comment