The Expiry Date validation rule:


    ISNEW()&& Expiry_Date__c >TODAY() + 182,

    ISCHANGED(Expiry_Date__c) && NOT(ISCHANGED( Partner__c)) 
|| NOT(PRIORVALUE(Expiry_Date__c) <TODAY() - 182))

In plain English: the Expiry Date must be within the next six months.

To change or extend the Expiry Date, either it must be within the past six months, or the Partner must also be changed. Additionally, it can´t be changed to a date in the past.

The idea is that the date must be set while the record is new, and can only be changed if that date passes, or if the Partner is changed altogether.

If the Partner is changed, or the Expiry Date passes (and is within the past six months), then the Expiry Date should be extendable/changeable.

Which brings us to the Extension Expiry Date validation rule:

    NOT(ISCHANGED( Partner__c)),
    PRIORVALUE(Expiry_Date__c) < TODAY() - 182,
    Expiry_Date__c >TODAY() + 91 
|| Expiry_Date__c <TODAY())  

If the record isn´t new, the Partner isn´t changed and the Expiry Date has been passed (and is within the past six months), then the Extension Expiry Date must be within the next three months, and can´t be changed to a date in the past either.

Now I have a Expiry Date: 12/12/2016 (a date that is within the past six months).

When I try to change it to 12/03/2017 (expecting the change to be successful), the error message for the first validation rule (the six-month rule) appears.

I´m not sure whether my logic is completely wrong, or I´m writing the "within the past six months" lines incorrectly - any ideas?

1 Answer 1


As near as I can tell, the && is taking precedence over the || in your first formula, which you can fix by adding some more parentheses:

    ISNEW()&& Expiry_Date__c >TODAY() + 182,
    ISCHANGED(Expiry_Date__c) &&
    (NOT(ISCHANGED( Partner__c)) || NOT(PRIORVALUE(Expiry_Date__c) <TODAY() - 182)))

I personally recommend avoiding mixing the two styles (AND/OR vs &&/||), because it can be harder to read.

(ISNEW() && Expiry_Date__c >TODAY() + 182) ||
 (ISCHANGED(Expiry_Date__c) &&
 (NOT(ISCHANGED( Partner__c)) || NOT(PRIORVALUE(Expiry_Date__c) <TODAY() - 182))))

Always make sure to use the appropriate amount of parentheses when mixing AND and OR (or && and ||), to make sure the correct logic is being evaluated.

Finally, you can use De Morgan's Laws to make it a bit less verbose:

( ISNEW() && Expiry_Date__c > TODAY()+182) ||
( ISCHANGED(Expiry_Date__c) &&
  NOT(ISCHANGED(Partner__c) && PRIORVALUE(Expiry_Date__c)<TODAY()-182)))

Here, we can say that NOT(A) || NOT(B) is the same as NOT(A && B).

  • Thanks! I´m still getting the error, but this simplifies things.
    – user34868
    Dec 16, 2016 at 18:27
  • 1
    @ESil Curious. It looks like it should work, based on the description you provided vs. what I wrote. I think we need to think about it more...
    – sfdcfox
    Dec 16, 2016 at 19:33

You must log in to answer this question.