Monday, June 1, 2015

Salesforce Lesson 4 - Notable Formula Logic Mistakes

Greetings aspiring Force.com developers,

Something like this does NOT mean anything if included with other AND conditions:
OR  (FieldX <> 'A', 
        FieldX <> 'B'
)

Why?  Because its always going to return true regardless of what FieldX value is.  If the value of FieldX happens to be 'A' its true because then FieldX <> 'B'.  If the value of FieldX happens to be 'B' its true because then FieldX <> 'A'.  If the value of FieldX happens to be 'Z' (or anything else) its true because then FieldX <> 'A'.

OK so don't do that - Im beggin.

Maybe you really want NEITHER value A or B here?  (Thats what I think when I see code like this anyway.)  In that case you want to say:
AND  (FieldX <> 'A', 
        FieldX <> 'B'
)

Although if you had this condition inside another AND condition group, as supposed in my first sentence, then just use:
FieldX <> 'A', 
FieldX <> 'B'

Generally speaking this construct is excessive and more complicated for no reason:
AND(AND(condition1, condition2), condition3)

Simplify to:  AND(condition1, condition2, condition3)

For the developer who needs to expand on a rule it can continue to get more complex so keep it as tight and clean as possible to begin with.