Skip to main content

Create Validation Rules

The Rundown

Noah Larkin can now track which accounts don’t have a support plan expiration date, but he also wants to ensure that, going forward, all users enter the support plan expiration date when the Has Support Plan checkbox is selected on an account. Allison Wheeler has a similar request. She’d like to ensure that sales reps enter a Close Reason whenever an opportunity is lost. 

Take care of Noah’s and Allison’s requests by creating validation rules, which allow you to specify your own criteria to prevent users saving invalid data in one or more fields.

Note: An important point to keep in mind when working with validation rules is the impact on existing data. Validation rules apply to both future data and current data so the admin may need to populate the required data of the existing records to ensure any future integrations aren't blocked. 

Create Validation Rules

First, create an account validation rule that forces users to enter a Support Plan Expiration Date when Has Support Plan is selected.

  1. From Setup, click Object Manager and select Account.
  2. Select Validation Rules, then click New.
  3. For Rule Name, enter: Support_plan_expiration_date_required
  4. Ensure Active is selected.
  5. For Description, enter: Support plan expiration date is required when account is marked as having support plan.
  6. Enter this formula in the Error Condition Formula box: 
    Has_Support_Plan__c = True && ISBLANK(Support_Plan_Expiration_Date__c)
    Error Condition Formula screen showing Support plan expiration date validation rule formula.
  7. Click Check Syntax to ensure you have no errors.
  8. For Error Message, enter: You must enter an expiration date when an account has a support plan.
  9. Select Field as the Error Location and Support Plan Expiration Date as the Field.
  10. Click Save.

Next, create an opportunity validation rule to force users to enter a Close Reason when the opportunity Stage is Closed Lost.

  1. From Setup, click Object Manager and select Opportunity.
  2. Select Validation Rules, then click New.
  3. For Rule Name, enter: Close_reason_required_when_lost
  4. Ensure Active is selected.
  5. For Description, enter: A close reason is required when opportunity is closed lost.
  6. Enter this formula in the Error Condition Formula box:
    ISPICKVAL( StageName ,"Closed Lost") && ISBLANK(Close_Reason__c)
  7. Click Check Syntax to ensure you have no errors.
  8. For Error Message, enter: You must enter a close reason when opportunity is closed lost.
  9. Choose Field as the Error Location and Close Reason as the Field.
  10. Click Save.

You’ve created picklists, lookup filters, formula fields, and record types; set up custom record pages, page layouts, and field history tracking; and established validation rules. Using these tools, you’ve enabled the ops, sales, and service teams to do their jobs better and more efficiently by customizing how they work with the important data they need day to day. Good work, Admin!

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback