When you take inputs from Users, the most important thing to be considered is that we get clean and good data. For this purpose, Salesforce provide us the helpful feature called as Validation Rule to validate the fields depends on your business criteria.
Rules in Salesforce
There are five types of rules in Salesforce:
- Validation Rules
- Assignment Rules
- Auto-response Rules
- Workflow Rules
- Escalation Rules
Introduction To Validation Rules
Validation Rules is used to validate the user input while creating or manipulating the records. It allows you to define custom logic and error messages to ensure data integrity. This Validation Rules fire after clicking on the save button. It evaluates the data in one or more fields and return a value of True or False.
It return error message when the data entered by the user is invalid or we can say that when the validation rule return a value True, then an error message will be displayed on page.
Validation Rules consists of :
Formula: Criteria to validate business rule. If formula evaluates to true, validation error is thrown.
Error Message: This message will appear when condition formula is true.
Error Location: It defines location to display error message. The error message can be either displayed at the top of the page or below a specific field on the page.
Now, Let's get your hands dirty with it.
Business Case (Account Number Length Validation): Validates that the Account Number is exactly 10 digits.
- Go to Setup.
- From Object Manager, Open Account Object.
- On the bottom of the left sliding tab, you'll find Validation Rules, click on it. Then Click on New.
- Give a Rule Name, Let's name it Account_Number_Length (you can put any name of your choice).
- In Formula, put the below condition. This condition evaluates to true if the Account Number Field length is not equals to 10.
- Don't forget to check the syntax, to see if there's any error in it.
- Then enter an error message and Error Location is Account Number field.
- Click on Save.
- Create Formula to ensure that email address format is valid
- Validation rule to validate the Phone Number Length is exactly 10.
- Validate that the Case status is Re-opened only when the case is opened again.
- Validate that the Date Field value is a weekday ( not Saturday and Sunday).
- Use Validation to check that user cannot change the Closed Date of an opportunity to a previous date.
Comments