0

I have a Primary Department picklist that controls a Division picklist. I need the Division field to become mandatory if the Primary department picklist equals "Medicine", "Surgery", or "Pediatrics".

This is my validation rule so far:

and(
if(ISPICKVAL(PrimaryDepartment__c, "Medicine"),
ISPICKVAL(Division__c, ""),
if(ISPICKVAL(PrimaryDepartment__c, "Surgery"),
ISPICKVAL(Division__c, ""),
if(ISPICKVAL(PrimaryDepartment__c, "Pediatrics"),
ISPICKVAL(Division__c, ""),false)))
)
1
  • 1
    Have you tried doing this with dependent picklists/required attributes on page layout?
    – sfdcfox
    Commented Dec 11, 2018 at 19:59

2 Answers 2

2

Please note that the most efficient way to check multiple picklist values is to use a CASE statement:

1 = CASE(
    MyPicklist__c,
    "Value A", 1,
    "Value B", 1,
    "Value C", 1,
    0
)

Now you simply have to fit this pattern into an AND clause where your other argument is the field being blank:

AND(
    ISPICKVAL(OtherPicklist__c, ""),
    1 = CASE(...)
)
4
  • Thanks Adrian! This is what I came up with: and( ispickval(Division__c, ""), 1=case( PrimaryDepartment__c, "Medicine", 1, "Surgery", 1, "Pediatrics", 1, 0) ) However, the Division field becomes required when I select any value from PrimaryDepartment. Where did I go wrong. Commented Dec 11, 2018 at 21:20
  • @KevinWollenberg Even when you select a value not included in your CASE statement? The fallback value is 0, meaning that statement should be false, and hence the entire AND statement.
    – Adrian Larson
    Commented Dec 11, 2018 at 21:31
  • Silly mistake, I had the field marked as required on the page layout. The validation rule works as expected. Thanks again! Commented Dec 12, 2018 at 15:10
  • @KevinWollenberg If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.
    – Adrian Larson
    Commented Dec 12, 2018 at 15:11
-2
AND(
    ISPICKVAL(picklist_name__c, 'PickList Value'),
    ISBLANK(field1__c)
)
1
  • 1
    Welcome to SFSE! Please take the tour and read How to Answer. Right now, this answer is what we call a code dump. Code dumps tend to be poor answers because they don't help people understand what the issue was, or why the fix works. They also tend to generate a lot of back-and-forth in the comments like "that didn't work" and "try this instead" which makes it hard for other people with similar problems to follow. Generally speaking, the more explanation you can give, the better.
    – Derek F
    Commented Jul 30, 2019 at 11:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .