Skip to main content
Estimación de tiempo

Create a Validation Rule

Follow Along with Trail Together

Want to follow along with an expert as you work through this step? Take a look at this video, part of the Trail Together series. 

Note

Accessibility

This step requires some additional instructions for screen reader users. To access a detailed screen reader version of this step, click the link below:

Open 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 the validation criteria aren't met then the record does not save. If a rule's criteria aren't met, users see a custom error message and the record doesn't save. 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. Click the gear icon Gear icon and select Setup.
  2. Click the Object Manager tab.
  3. Click Opportunity.
  4. Click Fields & Relationships, then click New.
  5. Select Date, then click Next.
  6. For Field Label, enter Delivery Schedule Date.
  7. Click Next, then complete Step 3.
    • In the Read-Only column header, select the checkbox.
    • In the Read-Only column, deselect the Standard User and System Administrator checkboxes.
  1. Click Next, then click Save.

Now create a validation rule on the Opportunity object.

  1. From the Opportunity Object Manager, scroll down and click Validation Rules.
  2. Click New, 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 list, select ISPICKVAL, then click Insert Selected Function.
  2. In the formula, highlight picklist_field.
  3. Click Insert Field, select Stage from the second list, and then click Insert. Note that Stage will convert to StageName in the formula.
  4. In the formula, highlight text_literal, and enter "Closed Won" (including the quotation marks).
  5. Click at the end of the formula to position the cursor.
  6. Click Insert Operator, then select && And.
  7. Click Insert Operator, then select ( Open Parenthesis.
  8. Click Insert Field, select Delivery Schedule Date from the second list, then click Insert.
  9. Click Insert Operator, then select - Subtract
  10. Click Insert Field, select Close Date from the second list, then click Insert.
  11. Click Insert Operator, then select ) Close Parenthesis.
  12. Click Insert Operator, then select > Greater Than and enter 14 at the end of the formula.
  13. Verify that the formula looks like this:
    • ISPICKVAL( StageName , "Closed Won") && ( Delivery_Schedule_Date__c - CloseDate ) > 14
  1. Click Check Syntax.
    Delivery Date Formula Screenshot
  2. 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

  3. Click Save.

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.

Comparta sus comentarios sobre Trailhead en la Ayuda de Salesforce.

Nos encantaría conocer su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios cuando quiera desde el sitio de la Ayuda de Salesforce.

Más información Continuar para compartir comentarios