Are you ready to discover the Validation rules in Salesforce? If you are a salesforce developer, you must know about validation rules in Salesforce. Generally, we know that Validation means maintaining the proper output. So technically Validation in salesforce is done to improve the quality of data or information which is being used in implementing software. In this blog, I am going to explain the importance of these validation rules in Salesforce, why saleforce.com develops this validation rule and its limitations. This blog may help those who want to be master in Salesforce concepts. Let’s start learning;
Validation rules in Salesforce are used to improve the quality of data. These validation rules verify the data when the user enters a data record to maintain the standards. Validation rules in Salesforce also consist of formulas and expressions to evaluate the data record in one or more fields and also returns the output either in “true” or “ false” formats. Validation rules also add the error messages to which will be displayed in the output when the user returns the “true“ because of an invalid value.
After these validation rules, users can perform the below tasks such as;
1. User can choose to create a data record and also can able to edit already existing data records.
2. After this user choose the “save” button to save all the modified data records.
3. Validation rules can be verified in two ways:
a. If all the data values are valid and also you have saved the record.
b. suppose you have uploaded the invalid data, you will get an error message and this data record will not be saved.
4. User can also perform necessary changes to the data record and click the save button.
There are 5 steps used to process the validation rules in the following order;
1. Perform validation rules
2. Assignment rule
3. Auto-response rule
4. Workflow rule
5. Escalation rule.
Below are the few steps to manage the validation rules in Salesforce.com;
1. First define the validation rule
2. Next click on the Edit button to edit the name and also update the rule fields.
3. Now delete the validation rule.
4. Click on the validation rule button to view the details or clone the validation rule.
5. Now it’s time to activate the Validation rule button.
To define the validation rule, Salesforce.com comes up with two major prerequisites;
1. Required editions
2. User permissions.
Let me explain them one by one;
1. Required editions;
a. Available in: both salesforce classic and lightning experience.
b. Editions required are;
2. Contact manager
9. Database.com editions.
1. View the field validation rules.
2. To define or change the field validation rules.
3. View setup and Configurations
4. Perform customized applications.
Before performing any validation rule in Salesforce, you need to review the validation rules. The steps involved are;
a. First go to the management settings to find the relevant objects -> then click on “Validation Rules”.
b. then in the validation rule lists -> click the new validation rule.
c. Now enter the properties of the validation rules.
d. If you want to check the formula for errors, then click on check syntax.
To perform cloning of validation rules, the below are the important steps involved;
1. From the management settings for any relevant objects -> then go for validation rule
2. Then in the validation rules list -> now click on the name of the validation rule.
3. Now click the “clone” button.
4. User needs to define the new rules based on the original rule.
5. Now click save to finish the cloning process and save. Now if you want to create a new validation clone click the new button to create additional validation rules.
To activate the validation rule, you have to follow the below steps;
1. From the management settings -> now go to validation rules.
2. Now it’s time to click the Edit button -> now select the button to activate the validation rule.
3. To activate the validation rule -> select the active button -> save changes.
4. If you want to deactivate the validation rule -> deselect the active button -> save the changes.
Below are the few important fields used to validate the rules;
1. Rule name: this is a unique identifier of up to 40 characters with no space or no special character that can be used.
2. Active: The check box indicates that if the rule is enabled.
3. Description: It’s 255 characters or uses the less description that distinguishes the validation rule from others. This is used for internal purposes only.
4. Error condition formula: this is an expression field that is used to validate the fields of formula operators and fields.
5. Error message: This error message is displayed when user data fails the validation rule. If the organization uses the transaction workbench, the user can translate these error messages to the language salesforce support.
6. Error location: Determines where on the page to display the error next to the data field, then choose the field and select the field. If you find the error location field that will be deleted later. This field is available in the form of read-only. And this field will not be visible on the page layout.
Example 1: Sample account addresses validation rules:
Here the data field is: Description
Value: Now validates the account billing zip/postal code is in the correct data format if the billing country is Canada.
Formula: AND (OR (BillingCountry = “CAN”, BillingCountry = “CA”, BillingCountry = “Canada”),
NOT (REGEX (BillingPostalCode, “((?i) [ABCEHJKLMNPQRSTUVWXYAZ] \\d [A-Z]?\\S? \\d[A-Z] \\d)?”))))
Error Message: Canadian postal code should be in A9A 9A9 format.
Error Location: Billing Zip/Postal code.
Sample account Validation Rules:
Here you to check the Numeric account number;
Description: validates the account number is numeric if not then block it.
Formula: AND (ISBLANK (Account number), NOT (ISNUMBER (accountNumber)))
Error message: Account number is in numeric format
Error location: Account Number.
Description: validates the account number, this should be in Seven digits (If the account number is valid).
Formula: AND (ISBLANK (AccountNumber), LEN (accounNumber) <> 7 )
Error Message: Account number must be of seven digits.
Error location: Account number.
Description: Validates the account annual revenue is not a negative value and should not exceed $100 billion.
Formula: OR (
Annualrevenue < 0,
AnnualRevenue > 1000000000
Error message: Annual revenue cannot exceed 100 billion.
Error location: Annual Revenue.
Below are the basic tips for writing the validation rules:
1. If you have decided to perform validation, you have to go for all settings in the configuration tab; this can makes the record failed validation. This can include the following procedure such as assignment rule, field updates, filed-level security, and hidden fields on the page layout.
2. You should be careful and no need to create any contradiction validation rules for the same data fields. And users cannot save the record.
3. When referencing the data fields in any validation formula, and make sure that all the objects are deployed.
4. Now use the RecordType.Id merges data field in the formula to apply different validations for different types of records.
5. You don’t have to begin a validation rule formula with the IF function. Here Boolean expressions can work like this;
Correct: CloseDate < Today ()
Incorrect: If (CloseDate < TODAY (), TRUE, FALSE)
6. One more important thing is that, when a validation rule contains any fields like BEGINS or CONTAINS function, this processes the data fields as valid.
7. When you are using a validation rule this ensures that a number of fields contain many specific values if you using the ISBLANK function this doesn’t contain any data values.
The function is as follows;
OR (ISBLANK (field_c), field_c <> 1)
8. Avoid using the ISClosed or ISWon functions to merge the fields while performing the validation process.
1. Give instructions to Salesforce developer. Suppose if you get an error message like “invalid entry”, this doesn’t mean tell you that, what type of data entries are valid. So you have to use more specific terms like “close date must be after today”.
2. Always good use the field labels. Sometimes users may not know that label fields are failing to perform validations. This only happens when the error messages appear at the top of the page.
3. If you have a multilingual organization, it’s good to translate the error messages. With the help of translate workbench, you can translate the error messages.
4. Assigning the numbers to validate rules and error messages. This helps you to identify the source of error.
Learning this blog will help you to learn the important validation rules in Salesforce and how to use them. If you are a salesforce developer it’s always good to know about these Validation rules and their importance. I hope this blog may help a few of you to get the complete idea of validation rules and also Salesforce social community forums.
Batch starts on 20th Apr 2021, Weekday batch
Batch starts on 24th Apr 2021, Weekend batch
Batch starts on 28th Apr 2021, Weekday batch