0

I have a validation rule which fires when a lookup field is not empty. enter image description here

However, the validariont rule currently fires when the lookup is empty and says that field is not empty..

This is the validation rule:

AND(
    NOT(ISNEW()),
    OR(
        ISCHANGED(Manager__c),
        ISCHANGED(Agent__c),
        ISCHANGED(TeamDirector__c),
        ISCHANGED(Director__c)
    ),
    OR(
        NOT(ISBLANK(Manager__c)),
        NOT(ISBLANK(Agent__c))
    ),
    OR(
        NOT(ISBLANK(TeamDirector__c)),
        NOT(ISBLANK(Director__c))
    )
)

The validation has to fire when a team director (or a director) is filled on the same time that a manager (or an agent) and one of the 4 fields is modified.

I enabled the debug logs and it means that the TeamDirector__c field is not empty but I don't understand why, this is the result of the debug log:

Agent__c=null , TeamDirector__c=a0E0E000003WvDl , Manager__c=a0E0E000003YtTR , Director__c=null

Can you help me please?

Thanks

3
  • have you checked to see if you have any apex trigger, process builder, or workflow that is filling in one of those lookups? Your debug log shows TeamDirector having a value while the UI does not which indicates it was set by some automation on the update. Apr 21, 2021 at 16:01
  • I have an apex trigger with a before update context but validation rules fire before apex triggers?
    – Oupat
    Apr 21, 2021 at 16:15
  • See here. It runs custom validation rules after execution of before triggers again. Not to mention the whole thing will re-run if you update the same record in the after context (ex. workflow field update on same record). Apr 21, 2021 at 16:43

1 Answer 1

1

It fires because both Manager__c and TeamDirector__c are not null, so both ORs return true, thus the entire rule returns true, given this is not a new record and at least one field was changed. This should not be one validation rule, but at least two (preferably four, if I understand your intent), one for each field being validated. Trying to combine rules like this is not only complicated, but also prevents the UI from highlighting the errant fields, increasing cognitive load for the user.

1
  • What is an OR? It is not a new record but an update. I have an apex trigger with a before update context and I guess the error comes from the apex trigger because validation rules are fire after before update triggers?
    – Oupat
    Apr 21, 2021 at 16:21

You must log in to answer this question.

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