3

I am trying to put a validation rule together that fires if certain values on a picklist field are populated and then requires the user to populate a contact field called "DV Perpetrator / Opposing Party". The following syntax is firing, but once I populate the "DV Perpetrator / Opposing Party" field, it still will not allow me to save. How do I add the "DV Perpetrator / Opposing Party" criteria?

CASE(Presenting_Need_of_Case__c, "Legal - Divorce", 1, "Counseling - Domestic Violence",1, "Immigration - UVisa/VAWA", 1, "Shelter - Domestic Violence", 1, "Legal - Divorce", 1, "Legal - Order of Protection", 1, 0) = 1

  • So I've updated my rule to the following: CASE(Presenting_Need_of_Case__c, "Legal - Divorce", 1, "Counseling - Domestic Violence",1, "Immigration - UVisa/VAWA", 1, "Shelter - Domestic Violence", 1, "Legal - Divorce", 1, "Legal - Order of Protection", 1, 0) = 1 but i've realized I'm missing some criteria, what do I add to say if any one of those picklist values are populated then you are required to populate the contact field "DV Perpetrator / Opposing Party" ? – Kate Holden Jul 22 '16 at 19:00
3

You do not need an IF just use the OR conditions.

OR(
ISPICKVAL(Presenting_Need_of_Case__c,"Legal - Divorce"),
ISPICKVAL(Presenting_Need_of_Case__c,"Counseling - Domestic Violence"),
ISPICKVAL(Presenting_Need_of_Case__c,"Immigration - UVisa/VAWA"),
ISPICKVAL(Presenting_Need_of_Case__c,"Shelter - Domestic Violence"),
ISPICKVAL(Presenting_Need_of_Case__c,"Legal - Divorce"),
ISPICKVAL(Presenting_Need_of_Case__c,"Legal - Order of Protection")
)
  • Can you add some explanation about what was actually wrong? – Adrian Larson Jul 22 '16 at 17:55
2

While your function works, it's actually very inefficient. You should be able do something like this:

CASE(Presenting_Need_of_Case__c,
"Legal - Divorce",               1,
"Counseling - Domestic Violence",1,
"Immigration - UVisa/VAWA",      1,
"Shelter - Domestic Violence",   1,
"Legal - Divorce",               1,
"Legal - Order of Protection",   1,
0) = 1

This will reduce your compiled formula size by several kilobytes of code.

  • Couldn't you replace all the 1s with TRUE and the 0 with FALSE and then remove the equality comparison altogether? – Adrian Larson Jul 22 '16 at 18:01
  • @AdrianLarson You can't actually; you'll get an "invalid argument for case" error. I devised this workaround as a hack to work around that. – sfdcfox Jul 22 '16 at 18:03
  • Gotcha. I guess that makes sense. – Adrian Larson Jul 22 '16 at 18:05
  • So I've updated my rule to the following: CASE(Presenting_Need_of_Case__c, "Legal - Divorce", 1, "Counseling - Domestic Violence",1, "Immigration - UVisa/VAWA", 1, "Shelter - Domestic Violence", 1, "Legal - Divorce", 1, "Legal - Order of Protection", 1, 0) = 1 but i've realized I'm missing some criteria, what do I add to say if any one of those picklist values are populated then you are required to populate the contact field "DV Perpetrator / Opposing Party" ? – Kate Holden Jul 22 '16 at 18:58
  • @KateHolden (previous.formula) && ISBLANK(...), or AND( (previous.formula), ISBLANK(...)) – sfdcfox Jul 22 '16 at 19:09
1

Couple things.

  • You're actually missing commas.
    • OR syntax is OR(condition1, condition2, ...)
    • The "missing parenthesis" is the closing paren above, because without commas only one clause is required.
  • IF syntax is: IF(logical_test, value_if_true, value_if_false)

So it should actually look like:

IF(OR(
    ISPICKVAL(...),
    ISPICKVAL(...),
), "value if true", "value if false")

Or if you just want the Boolean value of logical_test, remove the IF function altogether.

  • 2
    A man got to make his comeback after being away for a while :(, let loose of these smaller goose Adrian :) – Rao Jul 22 '16 at 17:56
  • Hey I voted for you! +1 all around. :) Welcome back. @rao – Adrian Larson Jul 22 '16 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.