What is a validation rule?
A validation rule will conditionally prevent records from being saved.
Why use validation rules?
Use validation rules to ensure that users enter valid data when creating or updating records.
When an opportunity stage is “Closed/Lost”, the rep must enter the field “Reason Lost”:
For more examples:
Note, “Reason Lost” is NOT required when the opportunity stage is any other value. Therefore, making “Reason Lost” required on the page layout would not be appropriate. The key benefit of validation rules is that they conditionally prevent records from being saved.
For more examples:
Examples of Validation Rules
[Should / Long / Salesforce.com]
Creating validation rules
Validation rules can be created on most standard and custom objects, and use the same syntax as formulas.
- Validation rules will impact API usage, web-to-lead, and web-to-case submissions. Make sure to structure your validation rules so that they will not unintentionally interfere with these operations (such as rejecting a web-to-lead submission). It is possible to either add exceptions for users/profiles in the validation rule, or use custom settings in conjunction with validation rules (this second solution is likely more complex than what would be presented on the ADM201 exam). In some scenarios, you may need to disable validation rules when importing or updating data, and reinstate them afterwards.
- Too many validation rules can be frustrating from a user interface perspective, as the error is not presented until after the user attempts to save the record. Make fields required when possible (as they are indicated as required in the user interface), and employ other usability features as appropriate (for instance, create a page layout section for information required when an opportunity is lost if more than 1 field is captured).
- Some formula arguments (such as VLOOKUP) can only be used in validation rules.
Hi John, I’m curious if record type and profile play any role for importing data. Can it be done by any user? Im thinking what if fields are required in some cases (lets say enforced by layout) but not the other cases. Will that effect the data manipulation process?
Page layout does not impact the ability to import data, but validation rules will kick in (as will fields defined as required in the field definitions)
The import wizard is driven through import permissions while the data loader requires API access. Hope that helps 🙂
I have a validation rule that “rate” cannot be lower than $25, now I want anyone with a director or above hierarchy to be able to insert ANY rate. How would I accomplish this? Thanks, Sid.
Have your validation rule evaluate the $user global variable (e.g. look at the user profile). You’d also need to check that the value in that field has changed (priorvalue not equal to current value).
Should look something like this (not exact syntax):
$User.profile <> ‘profile allowed’ &&
Amount > 25 &&
PRIORVALUE(Amount) <> Amount
I am trying to create a validation rule that doesn’t allow a value greater than the current value. My custom field is Tank__c, can anyone help me with the syntax? I tried ISCHANGED but run into errors after the “greater than or equal to” symbol….any help would be appreciated!
Can you try this?
IF (Tank__c >PRIORVALUE(Tank__c),true, false)
Yep, great suggestion Carlos
I know that works, but just don’t understand why/how…
I know what is validating, just don’t understand the flow for true or false
Taking a second look at this – you actually don’t need the IF statement.
You can just put in:
Tank__c > PRIORVALUE(Tank__c)
The validation rule will fire if the result of the formula equates to true.
Spot on Carols, thanks. I was trying :
PRIORVALUE(Tank__c) >= ABS(Tank__c)
which requires a lesser tank value for ALL field updates on the record. Any explanation on how to narrow it down to a specific field rather than the entire record inputs? It’s apparently the IF operator. I never would have thought to use the true or false inputs on my own. All of this seems to make sense until I try the next field on my own : ) Thanks for the help.
AAAaaand I scrolled down to John’s reply. So if it wasn’t the IF operator, what made my formula apply to the entire record John?
If I want to write a validation rule to prevent duplicates, but not based on Name… is that possible with VLOOKUP? (From what I see and experiment with, VLOOKUP is only based on name.)
Do not create a record of ContactID (lookup field to Contacts) + Interest (from picklist, e.g. “Physics”).
*So the VLOOKUP needs to reference all the past ContactIDs AND Interest picklist values to prevent a duplicate combination.
* I thought of adding a formula field to create a unique ID (= ContactID + Interest)… but I don’t think I can reference that with a VLOOKUP since it’s not the Name field.
By the way — I love your site. It’s the most helpful thing I’ve found.
Taking ADM 201 on 12/30 (to fulfill a goal to take it this year). 🙂
Thanks- and good luck! 🙂
This article goes into a better explanation than I could easily: https://success.salesforce.com/answers?id=90630000000gyFzAAI
It looks like you are correct that it works on the name field. If you were using a dedup function on contacts, you could use the data.com duplicate blocker also.
Thanks for your speedy reply. I did see that Success article (I actually attempted to figure it out before I messaged you).
I appreciate your help.
In your example you could also use a workflow to concatenate the contact id and interest and store that value in a text field marked as unique.
You’re on the right track for vlookup but I’m not sure that it would work exactly the way that you want it to.
In the first “Consideration” there’s a link for more information about using custom settings in conjunction with validation rules. In the target of this link, it says “Notice that Default Organization Level Values are not set by default. This must be set in order for the validation rule to work. Click Manage [some odd characters] > New. ”
What are Default Organization Level Values? And, where are they set and why? (I’ve looked through Help & Training for this, but no luck. They don’t seem to have anything with OWD, which is the closest I was able to guess or find.)
Here’s another link that may help: http://www.buanconsulting.com/the-custom-setting-every-administrator-needs/
When you create a hierarchy based custom setting you need to set the default in order it to work correctly:
“Set the organization default behavior by clicking the New button above the Default Organization Level Value; The values will default appropriately in this instance to show that the default behavior will be to run validation rules, so you can just save.
Begin adding your exception profiles by clicking New”
Thanks, John. This actually a whole new can of worms because I had/have no idea what a custom setting is. Ack and yikes! That link talks about “a new Validation Rule Exception custom setting object”. Huh? For expediency’s sake, how likely is it that this topic will be on the cert exam?
Not very likely 🙂 I will look at updating the materials here to reflect.
Thanks, and yay!!! 🙂
This is an awesome feature.
Goal – Execs are being transferred leads that are not followed up on as their day to day tasks do not include managing leads. I want to remove the ability for someone to transfer them a lead BUT keep the ability for them to view reports/dashboards components on leads.
How could this be achieved? Is it possible to create a Validation Rule that prevents the transfer of a lead when the new Owner ID equals that of one of the execs or their associated profile?
how about this rule on the record owner (syntax is incorrect)
and (priorvalue(record owner.profile)=minion, record owner(profile)=executive)
Good idea Alex, something like that should work.
I have two page layouts (two diff record types using it) with a field “Salary” present in only one of the layouts. If I create a validation rule say SALARY__c 0, it fires for the page layout where I have not included salary. How do I avoid this?
This is just an example, could be any kind of validation that I just want to fire with one page layout, how do I do that?
You can’t based on page layout alone (as page layout is not a data element) – you would need to use record type (or some other field) within the validation rule.