Customize a Salesforce Object: Create Validation Rules

Study for the Administrator Certification Exam > Object Manager and Lightning App Builder (15%) > Customize a Salesforce Object > Create Validation Rules

The Rundown

  • enter support plan expiration date when Has Support Plan checkbox is selected
  • enter Close Reason when opportunity is lost

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. Setup > Object Manager > Account > Validation Rules > New
    • Rule Name: Support_plan_expiration_date_required
    • Active ✅
    • Description: Support plan expiration date is required when account is marked as having support plan.
    • Formula:
      • Has_Support_Plan__c = True && ISBLANK(Support_Plan_Expiration_Date__c)
    • Check Syntax
    • Error Message: You must enter an expiration date when an account has a support plan.
    • Error Location: ✅ Field: Support Plan Expiration Date
  2. Save

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

  1. Setup > Object Manager > Opportunity > Validation Rules > New
    • Rule Name: Close_reason_required_when_lost
    • Active ✅
    • Description: A close reason is required when opportunity is closed lost.
    • Formula:
      • ISPICKVAL( StageName ,”Closed Lost”) && ISBLANK(Close_Reason__c)
    • Check Syntax
    • Error Message: You must enter a close reason when opportunity is closed lost.
    • Error Location: ✅ Field: Close Reason
  2. 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!