Validation rules are an essential feature in Salesforce that ensures data quality by enforcing specific conditions when users input data into fields. Whether you’re a Salesforce Admin, Business Analyst, or Consultant, understanding and crafting effective validation rules for both standard and custom objects is critical to maintaining accurate and consistent data across your organization.
This blog post explores practical examples of validation rules for both standard and custom objects, complete with use cases, formulas, and error messages.
- Ensure the Rating field on the Account object is not blank when the Type field is set to “Customer.”
- On the Opportunity object, ensure the Close Date field is not set to a date in the past.
- On the Contact object, ensure the custom picklist field Role__c is selected when the Title field is “Manager” or “Director.”
- On the Opportunity object, ensure the custom field Discount__c is not greater than 20% unless the custom picklist field Approval Status__c is set to “Approved.”
- On the Case object, ensure the Priority field is set to “High” when the custom picklist field SLA__c is set to “High.”
- On the Product2 object, prevent the Active checkbox from being checked unless the custom field Availability_Date__c is populated.
- Ensure the Phone field is populated on the Lead object if the Lead Source field is set to “Web.”
- On the Opportunity object, prevent the Stage field from being set to “Closed Won” unless the Amount field is greater than 0.
- On the Case object, ensure the Escalation Reason field is populated when the Status field is set to “Escalated.”
- On the Account object, ensure the Annual Revenue field is greater than $1,000,000 if the Account Type field is “Enterprise.”
- On the Contact object, ensure the Email field is not left blank when the Contact Type custom picklist field is set to “Primary Contact.”
- On the Order object, ensure the End Date field is later than the Start Date field.
- On the Custom Object Project__c, ensure the Completion Date field is not set in the past.
- On the Campaign object, ensure the Expected Revenue field is greater than or equal to the Budgeted Cost field.
- On the Opportunity object, ensure the Probability (%) field is at least 50 when the Stage field is set to “Proposal/Quote.”
- On the Lead object, ensure the Email field contains “@” when the Lead Source is “Online Store.”
- On the Case object, ensure the Reason field is populated if the Case Origin field is “Phone.”
- On the Account object, prevent the Account Name field from exceeding 50 characters.
- On the Contact object, ensure the Phone field follows the format “(XXX) XXX-XXXX” when the Country field is “USA.”
- On the Order object, ensure the Order Amount field is greater than 0 when the Status field is “Confirmed.”
- On the Project__c object, prevent the Status__c field from being set to “Completed” unless the Completion Date__c is populated.
- On the Campaign object, ensure the Start Date is earlier than or equal to the End Date.
- On the Custom Object Expense__c, ensure the Approval Status__c is “Pending” when the Expense Amount__c exceeds $10,000.
- On the Opportunity object, prevent setting the Stage to “Closed Lost” if the Reason Lost__c field is blank.
- On the Opportunity object, ensure the Close Date is within the current fiscal year when the Stage field is set to “Closed Won.”
- On the Lead object, ensure the Company field is not “Test” or “Dummy” when the Industry field is populated.
- On the Case object, ensure the Priority field is “High” if the Case Type field is “Critical Issue.”
- On the Contact object, prevent the Birthdate from being a future date.
- On the Product2 object, ensure the Standard Price field is greater than 0 when the Active checkbox is selected.
- On the Order object, ensure the Shipping Address is filled when the Status field is “Shipped.”
- On the Event object, ensure the End Time is later than the Start Time.
- On the Custom Object Task__c, ensure the Priority__c custom field is not set to “High” if the Assigned To__c field is blank.
- On the Campaign object, ensure the Budgeted Cost is less than or equal to the Total Expected Revenue.
- On the Custom Object Invoice__c, ensure the Due Date__c is within 30 days of the Invoice Date__c.
- On the Opportunity object, ensure the Contact Role is populated when the Stage is set to “Negotiation/Review.”
- On the Custom Object Vendor__c, ensure the Phone Number is populated when the Vendor Type__c field is “Supplier.”
For More Questions, Visit