Create a Validation Rule | Trailhead Screen Reader Instructions

Introduction

Dirty data: It could be incomplete, inconsistent, outdated, duplicated, or full of spelling errors. No matter what, it leads to confusion, time waste, budget waste, and internal and external mistrust. And no one wants that. You’ve probably spent more time than you like cleaning up messy data in your org. But how do you keep data from getting dirty in the first place? The answer doesn’t involve bleach or hand sanitizer, just setting up a few rules, formulas, filters, and a flow.

 

Setting Limits with Validation Rules

Let’s start with validation rules, which allow you to set up business-specific criteria to prevent users from saving invalid data in one or more fields. A validation rule evaluates a formula upon record save. If a rule’s criteria aren’t met, users see a custom error message and the record doesn’t save. If a rule’s criteria are met, the record saves. Use validation rules to improve data quality by applying conditions, ensuring proper formatting, and enforcing consistency.

 

As the admin for AW Computing, your first keep-it-clean task is at the request of Allison Wheeler, the VP of Global Sales. She’s aiming to ensure deliveries for opportunities be scheduled within two weeks after an opportunity stage changes to closed won. Use a validation rule to set the time frame.

 

Before you set up the validation rule, it’s necessary to create a custom field, Delivery Schedule Date.

  1. Activate the Setup button and select Setup.
  2. Select the Object Manager tab.
  3. From the table of objects, press ENTER on the link for Opportunity.
  4. Select the Fields & Relationships tab, then activate the New Custom Field button.
  5. Select Date, then activate the Next button.
  6. For Field Label, enter Delivery Schedule Date.
  7. Activate the Next button, then complete the following steps:
    • In the Read-Only column header, select the checkbox.
    • In the Read-Only column, deselect the Standard User and System Administrator checkboxes.
  8. Activate the Next button, then activate the Save button.

 

Now create a validation rule on the Opportunity object.

  1. From the Opportunity Object Manager, select the Validation Rules tab.
  2. Activate the New Validation Rule button, then create a validation rule with these details.
    Field Value
    Rule Name Delivery_Schedule_14_Days_Or_Less
    Active Select
    Description Sets end date for initial delivery

Now, enter the error condition formula.

  1. From the Functions combo box, select ISPICKVAL, then TAB to the Insert Selected Function button and activate it.
  2. In the formula editor field located directly above the Check Syntax button, highlight the text picklist_field.
  3. Exit the form, then navigate up the page and activate the Insert Field button.
  4. Select Stage from the second combo box, and then activate the Insert button. Note that Stage will convert to StageName in the formula editor.
  5. In the formula editor field, highlight the phrase text_literal, and type the words "Closed Won" (including the quotation marks).
  6. Position the cursor at the end of the formula editor field.
  7. Exit the form and navigate up the page to locate Insert Operator. Press ENTER on this text, and a menu will expand below it. Press ENTER on the link for & concatenate. Note that your focus may jump, requiring you to navigate back down the page to locate the menu.
  8. Press ENTER on the Insert Operator text again, then select ( Open Parenthesis from the menu below.
  9. Activate the Insert Field button, select Delivery Schedule Date from the second combo box, then activate the Insert button.
  10. Press ENTER on the Insert Operator text, then select - Subtract from the menu of links below it.
  11. Activate the Insert Field button, select Close Date from the second combo box, then activate the Insert button.
  12. Press ENTER on the Insert Operator text, then select ) Close Parenthesis.
  13. Press ENTER on the Insert Operator text again, then select > Greater Than and type 14 at the end of the formula editor field.
  14. Verify that the formula looks like this. You can copy and paste the text if necessary:
    ISPICKVAL( StageName , "Closed Won") && ( Delivery_Schedule_Date__c - CloseDate ) > 14
  15. Activate the Check Syntax button.
  16. Next, enter the error message information.
    Field Value
    Error Message Dates of type delivery must be no later than 14 days after close date
    Error Location Field: Delivery Schedule Date
  17. Activate the Save button.

 

You’ve gotten off to a good start in the AW Computing dirty data prevention plan by creating a validation rule. Now move on to the next step, and have some good, clean fun with formula fields.

Click to return to the unit on Trailhead to verify this step.