What are Validation Rules?
It’s important to keep the data you collect in your CRM clean and consistent. One of the ways of ensuring consistent and valid information is through the use of a validation rule . A validation rule is rule on a field that verifies that the field meets certain criteria and prevents the User from saving the record until the conditions are met. The rule is written using Salesforce operators and functions.
When to Use Validation Rules
I usually use validation rules to check that a field has the proper type of text, for example, a “zip code” field should only contain numbers and dashes. I also use validation rules to check that certain fields have been copleted before moving a record to a new stage. For example, an opportunity should have an Amount before moving it into the third stage of a sales cycle. The Amount isn’t required in earlier stages, but it is required in later sale stages.
Validation Email Address Domains
One use case for a validation rule is to check that an “email” field type contains emails with a certain domain type. I am working with a client that only accepts educational institutions as cutomers. In order to be logged as a Contact in the system, the email domain must contain “.edu”. In this case the Contact record had two email address fields, the standard field “Email” and another field called “School Email Address”. This is the validation rule I used:
How the Email Validation Rule Works
This rule uses the RIGHT function that returns the first 4 characters starting from the right side of the field. In this case, the 4 characters shold contain some version of a ‘.’ and the letters ‘e’, ‘d’ and ‘u’. If the 4 characters contain anything other than that, such as “.com” or “.org”, the validation rule will evaluate to FALSE and the User will not be able to the record.
In this particular case, the client wanted a Contact record to be saved if the School Email Address was blank, the rule only applies of some type of email address IS entered in the field. That is why the last part of my function allows for the field to be empty, meaning the 4 characters from the right would be all blank.
See it In Action
I created the following video that explain how the validation rule works and shows you had to build it.
If you like this video, check out my channel for other helpful Salesforce tutorials.