The simplest implementation would be:
ISBLANK(Field1__c) != ISBLANK(Field2__c)
Next most accessible:
OR(
AND(ISBLANK(Field1__c), NOT(ISBLANK(Field2__c))),
AND(NOT(ISBLANK(Field1__c)), ISBLANK(Field2__c))
)
It doesn't make sense to return NULL
in your validation formula, the result should always be true
(error) or false
(no error). If you want to use the approach you have above, your else condition should be ISBLANK(Field2__c)
. To implement this strategy, however, you also need to apply the converse. The advantage of this approach is that you can add the error to each field.
Rule 1:
IF(
ISBLANK(Field1__c),
NOT(ISBLANK(Field2__c)),
ISBLANK(Field2__c)
)
Rule 2:
IF(
ISBLANK(Field2__c),
NOT(ISBLANK(Field1__c)),
ISBLANK(Field1__c)
)
Without seeing an example of a record that you think should be getting caught by this, it's between hard and impossible to tell you where you're going wrong unless there's a syntax error somewhere. I.e. you have a semantic error instead of a syntax error (and the validation rule alone generally isn't enough information to help with semantic errors).
Indenting formulas as you would if it were code is one of the best things you can do to help debug formulas (for validation rules, workflow rules, formula fields, etc...). Otherwise, it's just too easy for people to get lost in the sea of parenthesis.
Also, the longer your formula, the harder it is to read and reason about. You should be trying to make an effort to keep things short. For example, if you find yourself doing something like IF(<condition>, true, false)
, that can be reduced to simply <condition>
.
Applying that to the first section of your formula, you can reduce that long chain of IF()
to the following (after applying some basic boolean logic)
NOT(OR(
AND(
/* <something> = true can be reduced to simply <something> */
Send_to_Tier_1__c,
CONTAINS(Within_ILA_1__c, 'Green')
),
AND(
Send_to_Tier_2__c,
CONTAINS(Within_ILA_2__c, 'Green')
),
AND(
Send_to_Tier_3__c,
CONTAINS(Within_ILA_3__c, 'Green')
),
AND(
Send_to_Tier_4__c,
CONTAINS(Within_ILA_4__c, 'Green')
),
AND(
Send_to_Tier_5__c,
CONTAINS(Within_ILA_5__c, 'Green')
),
AND(
Send_to_Tier_6__c,
CONTAINS(Within_ILA_6__c, 'Green')
)
))
Also keep in mind that formulas are evaluated in a short-circuit manner. If you have
AND(condition1, condition2, condition3)
, and condition2
is false, then Salesforce will stop at that point and not evaluate condition3
. That's because any false result in an AND()
causes the entire AND()
to return false.
A validation rule trips when the result of evaluating the formula is true
. It doesn't matter if a single part evaluates to true, the entire thing has to evaluate to true.
$User.No_Validation__c
being true, Finalize_Approvers__c
being false, or ISCHANGED(Finalize_Approvers__c)
being false is enough to prevent your validation rule from firing, regardless of any other condition.
Best Answer
So that the validation rule fires if either field is blank you'd need to use