Corey Babka No Comments

Keeping Salesforce data accurate is one of the most important goals you will have.  If information is entered incorrectly, it will affect how it is pulled out in reports, dashboards, workflows, etc.  Even one letter missing or misspelled can make a filter show false instead of true.  For example if an Account is added with a Type of ‘Client’, it will not be included in a report showing all Accounts with the type of ‘Client’.

Validation rules help keep information consistent with your processes.  They check the value entered and if it does not meet the validation, it cannot be saved.  You can specify an error message in a validation rule to help guide the user to the proper data entry.  For this example, we will be placing a validation rule for Account records on a field named Account Number.

Creating a Validation Rule:

  1. Lightning: Go to Setup -> Object Manager and click  From the menu on the left, click Validation Rules.

Saleforce Classic: Go to Setup -> Customize -> Accounts -> Validation Rules.

  1. Click New to create a new Validation rule.
  2. Enter the Rule name (e.g., AccountNumber_has_8_characters).
  3. Add a description. It is a good idea to put a short description on all custom objects to make it easier to maintain them.

  1. Enter the formula to use to check the validation. In this case we are checking to see if the length of the data entered into the AccountNumber field is not equal to 8 so we can alert the user.For this example the formula is:  LEN( AccountNumber) != 8

  1. Click on the Check Syntax button to make sure the formula is correct. You will not be able to save the Validation Rule if the formula has syntax issues.
  2. Enter the text of the error message you want the user to see as well as where the message will be displayed. The error can show next to the field that needs to be corrected or at the top of the page beneath the red warning bar.

  1. Click on the Save button to save the Validation Rule.
  2. Test the Validation Rule by entering both an invalid entry and a valid one. If a valid entry in added the record will save successfully.  If the entry is not valid, the error message will display and tell the user what needs to be done.

Written by Becci Gearman


Leave a Reply

Your email address will not be published. Required fields are marked *