0

We have a validation rule for our approval process and it's not firing when a portion of the criteria has been met. I have tried everything and cannot seem to get this to work. What am I doing wrong?

This is the validation rule:

AND(
    ISCHANGED(Finalize_Approvers__c),
    Finalize_Approvers__c = true,

    IF(
        AND(
            Send_to_Tier_1__c = true,
            CONTAINS(Within_ILA_1__c, 'Green')
        ),
        false,

        IF(
            AND(
                Send_to_Level_2__c = true,
                CONTAINS(Within_ILA_2__c, 'Green')
            ),
            false,

            IF(
                AND(
                    Send_to_Level_3__c = true,
                    CONTAINS(Within_ILA_3__c, 'Green')
                ),
                false,

                IF(
                    AND(
                        Send_to_Level_4__c = true,
                        CONTAINS(Within_ILA_4__c, 'Green')
                    ),
                    false,

                    IF(
                        AND(
                            Send_to_Level_5__c = true,
                            CONTAINS(Within_ILA_5__c, 'Green')
                        ),
                        false,

                        IF(
                            AND(
                                Send_to_Level_6__c = true,
                                CONTAINS(Within_ILA_6__c, 'Green')
                            ),
                            false, 
                            true
                        )
                    )
                )
            )
        )
    ),
    IF(
        AND(
            OR(
                ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Southern CCO'),
                ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Central CCO'),
                ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Northern CCO')
            ),
            LLC_BI__TCE__c <= 50000000,
            Class_1_Highest_loan_Amount__c <= 50000000,
            Class_4_Highest_Loan_Amount__c <= 50000000,
            Class_8_Highest_Loan_Amount__c = 0,
            Class_9_Highest_Loan_Amount__c = 0
        ),
        false,

        IF(
            AND(
                OR(
                    LLC_BI__TCE__c <= 75000000,
                    Class_1_Highest_loan_Amount__c <= 50000000,
                    Class_4_Highest_Loan_Amount__c <= 50000000,
                    Class_8_Highest_Loan_Amount__c = 0,
                    Class_9_Highest_Loan_Amount__c = 0
                ),
                OR(
                    ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Southern CCO and Committee'),
                    ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Central CCO and Committee'),
                    ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Northern CCO and Committee')
                )
            ),
            false,

            IF(
                AND(
                    OR(
                        LLC_BI__TCE__c > 75000000,
                        Class_1_Highest_loan_Amount__c > 50000000,
                        Class_4_Highest_Loan_Amount__c > 50000000,
                        Class_8_Highest_Loan_Amount__c = 0,
                        Class_9_Highest_Loan_Amount__c = 0
                    ),
                    OR(
                        ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to CCO and Holding Company President')
                    )
                ),
                false, 
                true
            )
        )
    ),
    $User.No_Validation__c = FALSE
)

This is the part of the criteria that when met, is not firing:

IF(
    AND(
        OR(
            LLC_BI__TCE__c <= 75000000,
            Class_1_Highest_loan_Amount__c <= 50000000,
            Class_4_Highest_Loan_Amount__c <= 50000000,
            Class_8_Highest_Loan_Amount__c = 0,
            Class_9_Highest_Loan_Amount__c = 0
        ),
        OR(
            ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Southern CCO and Committee'),
            ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Central CCO and Committee'),
            ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to Northern CCO and Committee')
        )
    ),
    false,

    IF(
        AND(
            OR(
                LLC_BI__TCE__c > 75000000,
                Class_1_Highest_loan_Amount__c > 50000000,
                Class_4_Highest_Loan_Amount__c > 50000000,
                Class_8_Highest_Loan_Amount__c = 0,
                Class_9_Highest_Loan_Amount__c = 0
            ),
            OR(
                ISPICKVAL(Send_to_Director_of_Credit_or_CCO__c, 'Send to CCO and Holding Company President')
            )
        ),
        false, 
        true
    )
)
)

1 Answer 1

0

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.

You must log in to answer this question.

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