Sales Force Useful Validation Formulas
Sales Force Useful Validation Formulas
Sales Force Useful Validation Formulas
Available in: Contact Manager, Group, Professional, Enterprise, Unlimited, Developer, and Database.com Editions
User Permissions Needed To view field validation rules: To define or change field validation rules: View Setup and Configuration Customize Application
Use the following samples for validation rules in Salesforce and Force.com AppExchange apps, including: Account Validation Rules Contact Validation Rules Opportunity Management Validation Rules Quote Validation Rules Call Center Validation Rules User, Role, and Profile Validation Rules Account Address Validation Rules Date Validation Rules Number Validation Rules Cross Object Validation Rules Community Validation Rules (Answers and Ideas) Other Validation Rules
Field Formula:
Value
AND( OR(BillingCountry = "CAN", BillingCountry = "CA", BillingCountry = "Canada"), NOT(REGEX(BillingPostalCode, "((?i)[ABCEGHJKLMNPRSTVXY]\\d[A-Z]?\\s?\\d[A-Z]\\d)?")) )
Canadian postal code must be in A9A 9A9 format. Billing Zip/Postal Code
Formula:
Billing Zip Code does not exist in specified Billing State. Billing Zip/Postal Code
Note: This example uses the REGEX function; see Shipping Zip Code on page 3 if you are not familiar with regular expressions. Error Message: Error Location: Zip code must be in 99999 or 99999-9999 format. Billing Zip/Postal Code
Note: This example interprets a blank country as US. To use this example with other countries, remove the clause that checks the length of the country field. Also, validation rule criteria are case sensitive, so this rule is only enforced when the country is blank or USA in all capital letters. The rule is not enforced when the country is usa. Tip: You can also validate zip codes using a regular expression; for an example of a formula using a regular expression, see REGEX in the Salesforce online help. Error Message: Error Location: Zip code must be in 99999 or 99999-9999 format. Shipping Zip/Postal Code
Formula:
Note: This example interprets a blank country as US. To use this example with other countries, remove the clause that checks the length of the country field. Also, validation rule criteria are case sensitive, so this rule is only enforced when the country is blank or USA in all capital letters. The rule is not enforced when the country is usa. Error Message: Error Location: A valid two-letter state code is required.
Billing State/Province
Error Message: A valid two-letter province code is required. Error Location: Billing State/Province
Note: This example interprets a blank country as US. To use this example with other countries, remove the clause that checks the length of the country field. Also, validation rule criteria are case sensitive, so this rule is only enforced when the country is blank or USA in all capital letters. The rule is not enforced when the country is usa. Error Message: A valid two-letter state abbreviation is required. Error Location: Shipping State/Province
Error Message: A valid two-letter province abbreviation is required. Error Location: Shipping State/Province
Field Formula:
Value
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:" & "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)))
Error Message: A valid two-letter country code is required. Error Location: Billing Country
Formula:
Field Formula:
Value
Monday_Hours__c + Tuesday_Hours__c + Wednesday_Hours__c + Thursday_Hours__c + Friday_Hours__c > 40
Field Formula:
Value
OR( Socks_Found__c < 0, MOD( Socks_Found__c, 2) = 0 )
Salary range must be within $20,000. Adjust the Salary Max or Salary Min values.
Salary Max
Formula:
10
11
Field Formula:
Value
AND( OR(MailingCountry = "USA", ISBLANK(MailingCountry)), OR( AND(LEN(MailingPostalCode) <>5, LEN(MailingPostalCode) <> 10), NOT(CONTAINS("0123456789", LEFT( MailingPostalCode, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 2, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 3, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 4, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 5, 1))), AND( LEN(MailingPostalCode) = 10, OR( MID( MailingPostalCode , 6, 1) <> "-", NOT(CONTAINS("0123456789", MID( MailingPostalCode , 7, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 8, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 9, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 10, 1))) ) ) ) )
Note: This example interprets a blank country as US. To use this example with other countries, remove the clause that checks the length of the country field. Also, validation rule criteria are case sensitive, so this rule is only enforced when the country is blank or USA in all capital letters. The rule is not enforced when the country is usa. Tip: You can also validate zip codes using a regular expression; for an example of a formula using a regular expression, see REGEX in the Salesforce online help. Error Message: Error Location: Zip code must be in 99999 or 99999-9999 format.
Mailing Zip/Postal Code
12
Value
LEFT(Phone, 1) <> "+"
13
Field Formula:
Value
CASE( MOD( My_Date__c - DATE(1900, 1, 7), 7), 0, 1, 6, 1, 0) = 0
14
Field Formula:
Value
DAY(My_Date__c) <> IF(Month(My_Date__c)=12, 31, DAY(DATE(YEAR(My_Date__c),MONTH(My_Date__c)+1,1) - 1))
15
Formula:
16
Field Formula:
Value
AND( OR ( ISNEW(), ISCHANGED( CloseDate )), CloseDate < DATE( YEAR(TODAY()), MONTH(TODAY()), 1) )
Discounts on Opportunities
Field Description: Formula: Error Message: Error Location: Value Validates that a custom discount percent field is between 0 and 40%.
OR(Discount_Rate__c < 0, Discount_Rate__c > 0.40)
17
Field Formula:
Value
AND( OR( ISPICKVAL(StageName,"Closed Won"), ISPICKVAL(StageName,"Closed Lost")), (Amount > 50000), NOT(ISPICKVAL(Approval_Status__c ,"Approved")))
All high-value opportunities must be approved for closure. Click the Request Close button.
Top of Page
18
Field Formula:
Value
AND ( CASE( StageName, "Value Proposition", 1, "Id. Decision Makers", 1, "Perception Analysis", 1, "Proposal/Price Quote", 1, "Negotiation/Review", 1, "Closed Won", 1, 0) = 1, NOT(HasOpportunityLineItem) )
Opportunity products are required to advance beyond the Needs Analysis stage.
Top of Page
Formula:
19
Formula:
20
21
Field Formula:
Value
AND( ISCHANGED( Status ), NOT(ISPICKVAL(PRIORVALUE( Status ), "New")), ISPICKVAL( Status, "New") )
22
Field Formula:
Value
CompletionDate CompletionDate >= <= Case.CreatedDate Case.ClosedDate &&
The milestone Completion Date must occur after the date the case was created and before the case was closed.
Top of Page
Formula:
23
Formula:
Note: $Profile merge fields are only available in Enterprise, Unlimited, and Developer Editions.
24
Field Formula:
Value
AND( OR ( ISNEW(), ISCHANGED( CloseDate )), CloseDate < DATE( YEAR(TODAY()), MONTH(TODAY()), 1), $Profile.Name <> "Custom: System Admin" )
Note: $Profile merge fields are only available in Enterprise, Unlimited, and Developer Editions.
Consulting Discounts
25
Value Prevents users from saving consulting products with a discount over 15 percent.
AND(Line_Discount__c > 0.15, ISPICKVAL(Product2.Family, "Consulting"))
Training Discounts Field Description: Formula: Value Prevents users from saving training products with a discount over 20 percent.
AND(Line_Discount__c > 0.20, ISPICKVAL(Product2.Family, "Training"))
Formula:
26
Field Description:
Value Prevents users from deleting opportunity products after an opportunity is closed. Create the following validation rule example on opportunities. It uses a custom roll-up summary field on opportunities that counts the number of opportunity products on an opportunity.
AND(OR(ISPICKVAL(StageName, "Closed Won"), ISPICKVAL(StageName, "Closed Lost")), Number_of_Line_Items__c < PRIORVALUE(Number_of_Line_Items__c) )
Formula:
Formula:
Unable to create cases for this account because it is not signed up for support.
Top of Page
27
Field Formula:
Value
AND(Contact.Not_Longer_With_Company__c, NOT(IsClosed))
Error Message:
Unable to save this case because the related contact is no longer with the company. To continue, choose another contact.
Contact Name
Error Location:
Error Message:
28
Field Formula:
Value
OR(CONTAINS(Title, 'darn'), CONTAINS(Body, 'darn'))
Error Message:
Error Message:
29
Field Formula:
Value
AND( MailingState = "CA", NOT(REGEX(Drivers_License__c, "([A-Z]\\d{7})?")) )
Formula:
Request will cause a negative PTO balance. You must accept Negative PTO Balance terms.
I accept terms
30
Field
Value Two single digits (0-9):\\d{2} A dash Four single digits (0-9):\\d{4}
NOT( OR( ISBLANK(Social_Security_Number__c), REGEX( Social_Security_Number__c , "[0-9]{3}-[0-9]{2}-[0-9]{4}") ) )
Formula:
Valid Currency
Field Description: Value Validates selected currency against an explicit subset of active currencies in your organization using the Currency picklist. Use this example if you only allow some of the active currencies in your organization to be applied to certain types of records.
CASE(CurrencyIsoCode, "USD", 1, "EUR", 1, "GBP", 1, "JPY", 1, 0) = 0
Formula:
31
Field Formula:
Value
NOT( REGEX( Credit_Card_Number__c , "(((\\d{4}-){3}\\d{4})|\\d{16})?"))
Valid IP Address
Field Description: Formula: Value Ensures that a custom field called IP Address is in the correct format, four 3-digit numbers (0-255) separated by periods.
NOT( REGEX( IP_Address__c, "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.) {3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" ))
Error: IP Address must be in form 999.999.999.999 where each part is between 0 and 255.
IP Address
Website Extension
Field Description: Formula: Value Validates a custom field called Web Site to ensure its last four characters are in an explicit set of valid website extensions.
AND( RIGHT( RIGHT( RIGHT( RIGHT( RIGHT( RIGHT( RIGHT( RIGHT( ) Web_Site__c, Web_Site__c, Web_Site__c, Web_Site__c, Web_Site__c, Web_Site__c, Web_Site__c, Web_Site__c, 4) 4) 4) 4) 4) 4) 6) 6) <> <> <> <> <> <> <> <> ".COM", ".com", ".ORG", ".org", ".NET", ".net", ".CO.UK", ".co.uk"
32