function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LdynesLdynes 

Validation rule for Currency field

Hi,

 

Can any of you 'Super Smarties' help me with a validation rule that would say in effect:

 

If Billing country is CA then Currency must be CAD

If Billing country is US then Currency must be USD

 

Thanks to anyone that can help!

Best Answer chosen by Admin (Salesforce Developers) 
Steve :-/Steve :-/

Okay here you go.

 

OR(
AND(BillingCountry = "US", (TEXT(CurrencyIsoCode) <> "USD")),
AND(BillingCountry = "UK", (TEXT(CurrencyIsoCode) <> "EUR")),
AND(BillingCountry = "CA", (TEXT(CurrencyIsoCode) <> "CAD")))

Now in order for this to work, you're gonna have to create an additional VR for the Billing Address Country (if you haven't already done that).

 

AND ( 
NOT( $Profile.Name = "System Administrator"), 
OR( 
LEN(BillingCountry) <> 2, 
NOT( 
CONTAINS( 
"AD:AE:AF:AG:AI:AL:AM:AN:AO:AQ:AR:AS:AT:AU:AW:AX:AZ:BA:BB:BD:BE:BF:BG:BH:BI:BJ:BL:BM:BN:BO:BR:BS:" & 
"BT:BV:BW:BY:BZ:CA:CC:CD:CF:CG:CH:CI:CK:CL:CM:CN:CO:CR:CU:CV:CX:CY:CZ:DE:DJ:DK:DM:DO:DZ:EC:EE:EG:" & 
"EH:ER:ES:ET:FI:FJ:FK:FM:FO:FR:GA:GB:GD:GE:GF:GG:GH:GI:GL:GM:GN:GP:GQ:GR:GS:GT:GU:GW:GY:HK:HM:HN:" & 
"HR:HT:HU:ID:IE:IL:IM:IN:IO:IQ:IR:IS:IT:JE:JM:JO:JP:KE:KG:KH:KI:KM:KN:KP:KR:KW:KY:KZ:LA:LB:LC:LI:" & 
"LK:LR:LS:LT:LU:LV:LY:MA:MC:MD:ME:MF:MG:MH:MK:ML:MM:MN:MO:MP:MQ:MR:MS:MT:MU:MV:MW:MX:MY:MZ:NA:NC:" & 
"NE:NF:NG:NI:NL:NO:NP:NR:NU:NZ:OM:PA:PE:PF:PG:PH:PK:PL:PM:PN:PR:PS:PT:PW:PY:QA:RE:RO:RS:RU:RW:SA:" & 
"SB:SC:SD:SE:SG:SH:SI:SJ:SK:SL:SM:SN:SO:SR:ST:SV:SY:SZ:TC:TD:TF:TG:TH:TJ:TK:TL:TM:TN:TO:TR:TT:TV:" & 
"TW:TZ:UA:UG:UM:US:UY:UZ:VA:VC:VE:VG:VI:VN:VU:WF:WS:YE:YT:ZA:ZM:ZW:UK", 
BillingCountry))))

 

 

 

 

 

 

All Answers

Steve :-/Steve :-/

Which object are you using the Currency Code VR on?  The Account or the Opportunity?

Steve :-/Steve :-/

Okay here you go.

 

OR(
AND(BillingCountry = "US", (TEXT(CurrencyIsoCode) <> "USD")),
AND(BillingCountry = "UK", (TEXT(CurrencyIsoCode) <> "EUR")),
AND(BillingCountry = "CA", (TEXT(CurrencyIsoCode) <> "CAD")))

Now in order for this to work, you're gonna have to create an additional VR for the Billing Address Country (if you haven't already done that).

 

AND ( 
NOT( $Profile.Name = "System Administrator"), 
OR( 
LEN(BillingCountry) <> 2, 
NOT( 
CONTAINS( 
"AD:AE:AF:AG:AI:AL:AM:AN:AO:AQ:AR:AS:AT:AU:AW:AX:AZ:BA:BB:BD:BE:BF:BG:BH:BI:BJ:BL:BM:BN:BO:BR:BS:" & 
"BT:BV:BW:BY:BZ:CA:CC:CD:CF:CG:CH:CI:CK:CL:CM:CN:CO:CR:CU:CV:CX:CY:CZ:DE:DJ:DK:DM:DO:DZ:EC:EE:EG:" & 
"EH:ER:ES:ET:FI:FJ:FK:FM:FO:FR:GA:GB:GD:GE:GF:GG:GH:GI:GL:GM:GN:GP:GQ:GR:GS:GT:GU:GW:GY:HK:HM:HN:" & 
"HR:HT:HU:ID:IE:IL:IM:IN:IO:IQ:IR:IS:IT:JE:JM:JO:JP:KE:KG:KH:KI:KM:KN:KP:KR:KW:KY:KZ:LA:LB:LC:LI:" & 
"LK:LR:LS:LT:LU:LV:LY:MA:MC:MD:ME:MF:MG:MH:MK:ML:MM:MN:MO:MP:MQ:MR:MS:MT:MU:MV:MW:MX:MY:MZ:NA:NC:" & 
"NE:NF:NG:NI:NL:NO:NP:NR:NU:NZ:OM:PA:PE:PF:PG:PH:PK:PL:PM:PN:PR:PS:PT:PW:PY:QA:RE:RO:RS:RU:RW:SA:" & 
"SB:SC:SD:SE:SG:SH:SI:SJ:SK:SL:SM:SN:SO:SR:ST:SV:SY:SZ:TC:TD:TF:TG:TH:TJ:TK:TL:TM:TN:TO:TR:TT:TV:" & 
"TW:TZ:UA:UG:UM:US:UY:UZ:VA:VC:VE:VG:VI:VN:VU:WF:WS:YE:YT:ZA:ZM:ZW:UK", 
BillingCountry))))

 

 

 

 

 

 

This was selected as the best answer
LdynesLdynes

Thank you so much Steve, that's so awesome of you. I haven't had a chance to try it out yet, but I'll be sure to let you know.

Thanks again, you mde my Friday!

Steve :-/Steve :-/

No problem, you owe me a beer!  

http://beeradvocate.com/beer/profile/863/7971

 

<

 

rpr2rpr2

Thanks for posting the VR Stevemo.  Some time ago I was wanting to create a WFR with a field update to automatically make sure the right currency was selected, but alas the currency field can not be selected for a field update.  I never even thought about doing a VR rule instead.  Not quite as good, but does end up in the same place -- clean data!