Validation rule is a filter or a criteria that validates the data that is pushed into an application and verifies if the data that has been entered is in accordance to the set standards.
Example :
Let's say, there is a field that is used to enter the Age of a Student. But per the organization rule, no student should be allowed to join the course if the age is not more than 25 years. So here you may write a validation rule saying that the Age field should not be more than 25. In case the age entered is more than 25, then the record is not allowed to be saved. You would see an error when you enter the age more than 25.
Let me give you another example. Say that there's a field to enter the Product code. And per the rule of the organization, the Product code should always start with PR. In case you enter any code other than the one that begins with PR, you would encounter an error.
The benefits of Validation rules is that you can improve the quality of the data that is going into the database. You ensure, inappropriate data never gets into the system.
You write a formula / expression [Age__c >25] which would verify the data . This is a boolean expression, as such the result is either TRUE or FALSE. Please note that whenever the validation rule returns TRUE, you will not be able to save the data. You will be able to save the data / record, only if the validation rule is FALSE.
In other words, if you write a validation rule, you would just focus on writing an expression or a formula which may give the output as TRUE or FALSE . If its TRUE then the validation rule prevents from saving the record. This may be bit confusing in the beginning. I too had the same problem of understanding this, but gradually I set my mind.
In summary ; If you do not want to allow values greater than 25, then you would write the validation rule as IF (Age__c > 25, TRUE, FALSE) . Here the validation rule is fired if the age value is greater than 25.
After you have created a validation rule and enforced it on an object :
A user who may be creating a new record / modify an existing record , enters the value in the Age field then 2 things may happen -
1 - If the value of Age is greater 25, record is NOT saved.
2 - If the value of Age is less than or eq. to 25 , record is saved.
The below are the steps to create a validation rule :
Example :
Let's say, there is a field that is used to enter the Age of a Student. But per the organization rule, no student should be allowed to join the course if the age is not more than 25 years. So here you may write a validation rule saying that the Age field should not be more than 25. In case the age entered is more than 25, then the record is not allowed to be saved. You would see an error when you enter the age more than 25.
Let me give you another example. Say that there's a field to enter the Product code. And per the rule of the organization, the Product code should always start with PR. In case you enter any code other than the one that begins with PR, you would encounter an error.
The benefits of Validation rules is that you can improve the quality of the data that is going into the database. You ensure, inappropriate data never gets into the system.
You write a formula / expression [Age__c >25] which would verify the data . This is a boolean expression, as such the result is either TRUE or FALSE. Please note that whenever the validation rule returns TRUE, you will not be able to save the data. You will be able to save the data / record, only if the validation rule is FALSE.
In other words, if you write a validation rule, you would just focus on writing an expression or a formula which may give the output as TRUE or FALSE . If its TRUE then the validation rule prevents from saving the record. This may be bit confusing in the beginning. I too had the same problem of understanding this, but gradually I set my mind.
In summary ; If you do not want to allow values greater than 25, then you would write the validation rule as IF (Age__c > 25, TRUE, FALSE) . Here the validation rule is fired if the age value is greater than 25.
After you have created a validation rule and enforced it on an object :
A user who may be creating a new record / modify an existing record , enters the value in the Age field then 2 things may happen -
1 - If the value of Age is greater 25, record is NOT saved.
2 - If the value of Age is less than or eq. to 25 , record is saved.
How to create a validation rule in Salesforce
The below are the steps to create a validation rule :
- Go to the object whether Standard or Custom
Click path for Custom objects : Setup | Customize | select the Standard objects | Validation Rules
Click path for Standard objects : Setup | Create | Objects | select the custom object | click new in the Validation rules
Validation Rules |
- Enter the properties of the validation rule.
- In the box below , you need to type in Age__c > 25 .
Error Condition Formula
Example:Discount_Percent__c>0.30More Examples ... Display an error if Discount is more than 30% If this formula expression is true, display the text defined in the Error Message area Functions ABS(number) Returns the absolute value of a number, a number without its sign
Help on this functionError Message
- Check your formula
- Click Save / Save and New per your requirement.
Comments
Post a Comment