I’ve recently written a couple Salesforce validation rules that I wanted to document and share for those trying to do something similar. First, let’s start with how to create a validation rule in Salesforce.
It is actually very easy to create a validation rule. Here are the steps…
- Click on Your Name -> Setup
- Under App Setup, click Customize
- Select at what level you want to apply a validation rule: Lead, Contact, Opportunity, etc
- Click Validation Rules
- Click New
Then to create a validation rule, you need to write a formula that if it does not validate to true, will return an error message that will then require the sales person to complete an action in order to make your rule validate to true.
In this first example, we wanted to start collecting data on opportunities that were older than 100 days. Why were the deals slipping? Budget? Infrastructure delays? Still testing our product? Just not responding? To do this, we decided to create a new field called “Deal Slip Reason”. If the “Deal Slip Reason” was blank and a sales person tried to edit/save an opportunity that had a “Close Date” of greater than 100 days after the “Create Date”, we would display a message alerting the sales person to complete the “Deal Slip Reason” field.
Here’s the validation rule that we used:
CloseDate – DATEVALUE(CreatedDate) > 100,
ISBLANK(TEXT( Deal_Slip_Reason__c ))
Another piece of data that we wanted to collect was the “Demo VDIO Phase” of any prospective leads that were being converted to a contact/opportunity . This meant that we needed to first validate that the “Partner” field was either blank or “N/A” as we didn’t want to ask this question if reseller partners or strategic partners were being converted this this demo phase is irrelevant to them. Next, we only wanted to apply this rule to those that were being converted and the “Demo VDI Phase” field was blank. So, here’s the complete rule we used:
OR (ISBLANK(TEXT(Partner__c)) && IsConverted && ISBLANK(TEXT(Demo_VDI_Phase__c)), TEXT(Partner__c) = “N/A”) && IsConverted && ISBLANK(TEXT(Demo_VDI_Phase__c))
Hopefully these examples of a couple of the Salesforce validation rules that I have written will help you to write some of yours. As I write more rules, I will be sure to update this post.