# Validation Rule CASE() function

I have this validation rule which works perfectly :

``````IF(ISPICKVAL( StageName , "Case1"), Probability != 100,
IF(ISPICKVAL( StageName , "Case2"),  Probability != 0,
IF(ISPICKVAL( StageName , "Case3"),  Probability != 10,
IF(ISPICKVAL( StageName , "Case4"),  Probability != 20,
IF(ISPICKVAL( StageName , "Case5"),  Probability != 30,
IF(ISPICKVAL( StageName , "Case6"),  Probability != 40,
IF(ISPICKVAL( StageName , "Case7"),  Probability != 50,
IF(ISPICKVAL( StageName , "Case8"),  Probability != 60,
IF(ISPICKVAL( StageName , "Case9"),  Probability != 70,
IF(ISPICKVAL(StageName  , "Case10"),  Probability != 80,
IF(ISPICKVAL( StageName , "Case11"),  Probability != 90,
Probability = 0)))))))))))
``````

As you can see if my StageName is "Case1" and my probability is not "100%", an error message will be send to the user.

My question is, how can i do the same work with the function CASE()? I saw Documentation about function Case() but i don't understand how it works for my case in particular.

Any help will be appreciated.

You can move the `Probability !=` outside of the CASE, resulting in a much more legible formula:

``````(Probability*100) != CASE(StageName,
"Case1", 100,
"Case2", 0,
"Case3", 10,
"Case4", 20,
"Case5", 30,
"Case6", 40,
"Case7", 50,
"Case8", 60,
"Case9", 70,
"Case10", 80,
"Case11", 90,
IF(Probability=0,100,Probability))
``````

Here, case returns a particular value (100, 0, etc), and it is compared to the Probability field as a percentage. The "default" condition is used to emulate "if stage is none of the prior values, and probability is zero, display an error".

• Edit : @sfdcfox Actually i cannot save anything now, even if probability is relied to the good stage name i got the error message Jul 21, 2017 at 14:06
• @VERYNET This should definitely work, as I tested it in my dev org. Make sure that your spellings are correct.
– sfdcfox
Jul 21, 2017 at 14:11
• i'm pretty sure it does not work. I did just one, Case1, 100 and when i do a modification by Case1 and probabilty 100% i have the error message Jul 21, 2017 at 14:13
• i found the problem Its "Case 1", 1.00 => because percentage, Case 3 "0.10" etc ... Jul 21, 2017 at 14:15
• @VERYNET Yeah, that's kind of odd behavior. I've edited the answer, but that should work for you.
– sfdcfox
Jul 21, 2017 at 14:18