Part III. 2. Validation in Salesforce



Introduction to Validation Rules

Validation rules verify that data entered by users in records meet the standards you specify before they can save it. A validation rule can contain a formula or expression that evaluates the data in one or more fields and returns a value of “True” or “False.” Validation rules can also include error messages to display to users when they enter invalid values based on specified criteria.

Using these rules effectively contributes to quality data. For example, you can ensure that all phone number fields contain a specified format or that discounts applied to certain products never exceed a defined percentage.

Defining Validation Rules

You can create validation rules for objects, fields, campaign members, or case milestones. In these steps, we’ll create a validation rule that fires when a user tries to save an account with an account number of incorrect length.

Creating a Validation Rule

  1. From Setup, go to Object Manager and click Account.
  2. In the left sidebar, click Validation Rules.
  3. Click New.
  4. Enter the following properties for your validation rule:
    1. Rule Name: Account_Number_8_Characters
    2. Error Condition Formula:  LEN( AccountNumber) != 8
  5. Error Message: Account number must be 8 characters long.
  6. To check your formula for errors, click Check Syntax.
  7. Click Save to finish.

Here’s how a validation rule’s error message can appear when a user types an incorrect phone number format into a field.

This training information is very useful to learn about validation in Salesforce.