validation rules
validation rules
Validation rules verify that data entered by users in records meets the
standards you specify before they can save it.
A validation rule can contain a formula or expression that evaluates
the data in one or more fields and returns a value of “True” or “False.”
When the validation rule returns a value of "True", this confirms that
the data entered by the user contains an invalid value.
Validation rules can also include error messages to display to users
when they enter invalid values based on specified criteria.
_________________________________________________________
For example, you can ensure that all phone number fields contain a
specified format or that discounts applied to certain products never
exceed a defined percentage.
_________________________________________________________
Description: Validates that a custom date field contains a date within the curre
Formula: YEAR( My_Date__c ) <> YEAR ( TODAY() )
Error Message: Date must be in the current year.
Field Value
Error Location: My Date
Number Range Validation
In the example, the validation rule determines if the difference between
two values (Salary Max and Salary Min) is greater than $20,000. A value
of "True" indicates that the data entered by the user contains an invalid
value. That is, if the user enters two values whose difference exceeds the
$20,000 salary range, the validation rule returns a response of "True" and
sends an error message.
Field Value
Description: Validates that the range between two custom fields, Salary Min a
greater than $20,000.
Formula: (Salary_Max__c - Salary_Min__c) > 20000
Error Salary range must be within $20,000. Adjust the Salary Max or Salary
Message:
Error Salary Max
Location:
Website Extension
The AND function returns a value of "True" if all values in the formula are
true, and a value of "False" if one or more values are false. The <> (Not
Equal) operator determines if a value is not equal to another value. In the
example, if the user enters a website URL with an extension that is not
equal to all six of the valid extensions, the validation rule returns a
response of "True" and sends an error message. If the user enters a
website URL with an extension that is identical to one of the valid
extensions, the validation rule returns a response of "False" and does not
send an error message, because the data the user entered is valid.
Field Value
Description: Validates a custom field called Web Site to ensure that its last four
explicit set of valid website extensions.
Formula: AND(
RIGHT( Web_Site__c, 4) <> ".COM",
RIGHT( Web_Site__c, 4) <> ".com",
RIGHT( Web_Site__c, 4) <> ".ORG",
RIGHT( Web_Site__c, 4) <> ".org",
RIGHT( Web_Site__c, 4) <> ".NET",
RIGHT( Web_Site__c, 4) <> ".net"
)
Copy
Error Web Site must have an extension of .com, .org, or .net .
Message:
Error Web Site
Location:
Valid Billing Country
The OR function returns a "True" response if one or more expressions in
the formula are true, and returns a "False" response if all expressions are
false. The LEN function returns the number of characters in a specified
text string. In the example, the validation rule determines if the value
that the user entered for a Billing Country code is either one character
(instead of the required two), or does not contain one of the valid two-
character codes. If either of these conditions is true, the validation rule
returns a value of "True" and sends an error message. If the user enters
a valid Billing Country code, both expressions in the formula are false: the
LEN is not 1, and the data does contain one of the valid values. In this
case, the validation rule returns a value of "False" and does not send an
error message.
Field Value
Description: Validates that the account Billing Country is a valid ISO 3166 two-l
Formula: OR(
LEN(BillingCountry) = 1,
NOT(
CONTAINS(
"AF:AX:AL:DZ:AS:AD:AO:AI:AQ:AG:AR:AM:" &
"AW:AU:AZ:BS:BH:BD:BB:BY:BE:BZ:BJ:BM:BT:BO:" &
"BA:BW:BV:BR:IO:BN:BG:BF:BI:KH:CM:CA:CV:KY:" &
"CF:TD:CL:CN:CX:CC:CO:KM:CG:CD:CK:CR:CI:HR:" &
"CU:CY:CZ:DK:DJ:DM:DO:EC:EG:SV:GQ:ER:EE:ET:FK:" &
"FO:FJ:FI:FR:GF:PF:TF:GA:GM:GE:DE:GH:GI:GR:GL:" &
"GD:GP:GU:GT:GG:GN:GW:GY:HT:HM:VA:HN:HK:HU:" &
"IS:IN:ID:IR:IQ:IE:IM:IL:IT:JM:JP:JE:JO:KZ:KE:KI:" &
"KP:KR:KW:KG:LA:LV:LB:LS:LR:LY:LI:LT:LU:MO:MK:" &
"MG:MW:MY:MV:ML:MT:MH:MQ:MR:MU:YT:MX:FM:MD:MC:"
Field Value
"MC:MN:ME:MS:MA:MZ:MM:MA:NR:NP:NL:AN:NC:NZ:NI:" &
"NE:NG:NU:NF:MP:NO:OM:PK:PW:PS:PA:PG:PY:PE:PH:" &
"PN:PL:PT:PR:QA:RE:RO:RU:RW:SH:KN:LC:PM:VC:WS:" &
"SM:ST:SA:SN:RS:SC:SL:SG:SK:SI:SB:SO:ZA:GS:ES:" &
"LK:SD:SR:SJ:SZ:SE:CH:SY:TW:TJ:TZ:TH:TL:TG:TK:" &
"TO:TT:TN:TR:TM:TC:TV:UG:UA:AE:GB:US:UM:UY:UZ:" &
"VU:VE:VN:VG:VI:WF:EH:YE:ZM:ZW",
BillingCountry)))
Copy
Error Message: A valid two-letter country code is required.
Error Location: Billing Country