0

I have this validation rule that I cannot understand why it would still be firing for these lost code values. I've tried copying and pasting the lost code values from the picklist with no luck. If anyone has some suitable methods to sus why it could still be firing for those values that would be amazing.

AND(
ISCHANGED(StageName),
ISPICKVAL(StageName,"Closed Lost"),
ISNULL(Diagnostic_Completion_Date__c),
Expansion_Opportunity__c = FALSE,
OR(
NOT(ISPICKVAL(Lost_Code__c,"Non-Responsive / Unknown")),
NOT(ISPICKVAL(Lost_Code__c,"Disqualified")))
)

1 Answer 1

1

Your problem is the OR statement. If Lost Code is "Non-Responsive / Unknown", it will not be "Disqualified", and vice versa. In other words, the OR condition will always be true. It should be AND. In addition, I believe you're using AND when you meant to use OR (as in, "if these three fields are not set properly, trigger an error"). Also, I feel like this should be at least three different validation rules, because you won't be able to show an error on a relevant field.

Your original formula should look like:

AND(
ISCHANGED(StageName),
ISPICKVAL(StageName,"Closed Lost"),
ISNULL(Diagnostic_Completion_Date__c),
Expansion_Opportunity__c = FALSE,
NOT(ISPICKVAL(Lost_Code__c,"Non-Responsive / Unknown")),
NOT(ISPICKVAL(Lost_Code__c,"Disqualified")))

Or, with de Morgan's Laws, we can convert the AND(NOT(),NOT()) into a NOT(OR()), as in:

AND(
ISCHANGED(StageName),
ISPICKVAL(StageName,"Closed Lost"),
ISNULL(Diagnostic_Completion_Date__c),
Expansion_Opportunity__c = FALSE,
NOT(OR(ISPICKVAL(Lost_Code__c,"Non-Responsive / Unknown"),
       ISPICKVAL(Lost_Code__c,"Disqualified")
      )
   )
)

What I believe you're trying to do is to check if any of the three fields are set incorrectly, which would look like this:

AND(
  ISCHANGED(StageName),
  ISPICKVAL(StageName,"Closed Lost"),
  OR(
    ISNULL(Diagnostic_Completion_Date__c),
    Expansion_Opportunity__c = FALSE,
    AND(
      NOT(ISPICKVAL(Lost_Code__c,"Non-Responsive / Unknown")),
      NOT(ISPICKVAL(Lost_Code__c,"Disqualified"))
    )
  )
)

As a practical matter, from a UX perspective, you should write one validation rule per field so you can attach the error to the appropriate field.

You must log in to answer this question.

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