function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDCDevQASFDCDevQA 

Issue with Date and Month Validation Rule on Close Date

I'm trying to create a validation rule that if a picklist labeled "Category" is set to "Fall" then the Close Date must be September 1st (year doesn't matter).  I would also then expand the rule to cover the values of Winter, Spring and Summer and their corresponding dates but right now I am getting stuck on just the day and month.  I can validate just the day or just the month and it works as it should for those individual parts, but when I put the parts together it breaks.

 

So I can get it to work with this:

AND(IsPickVal(Category__c, "Fall"), Day(CloseDate)<>1)

OR this:

AND(IsPickVal(Category__c, "Fall"), Month(CloseDate)<>9)

 

But once I do this it stops checking the day and only validates on the month.

AND(IsPickVal(Category__c, "Fall"), Day(CloseDate)<>1, Month(CloseDate)<>9)

 

Any ideas as to why this is breaking and what I can do about it?

Thanks,

Amanda

 

SporterSporter

I may have the months wrong but I believe this is what you want.

 

 

IF(ISPICKVAL( Category__c , "Winter") && (MONTH(CloseDate)<>12 && DAY(CloseDate) <> 1), true, 
IF(ISPICKVAL( Category__c , "Spring") && (MONTH(CloseDate)<>3 && DAY(CloseDate) <> 1), true, 
IF(ISPICKVAL( Category__c , "Summer") && (MONTH(CloseDate)<>6 && DAY(CloseDate) <> 1), true, 
IF(ISPICKVAL( Category__c , "Fall") && (MONTH(CloseDate)<>9 && DAY(CloseDate) <> 1), true, false))))

 

 

SFDCDevQASFDCDevQA

Nope.  With that code it is still recognizing if the Month is in error but not the day.  Any other ideas?

 

Thanks,

Amanda

SporterSporter

Could you run through a few steps and what response they should produce such as I enter this day and month and this category and I should get an error or not. I should be able to work from there.

SFDCDevQASFDCDevQA

You had the idea with the code you sent, it just did the same as mine and would only validate the month and not the day.  So to take just a piece of it as an example:  If the category is Fall then the Close Date should be September 1st (year doesn't matter).  So if the month is anything other than september (9) then it should trigger the validation rule and if the day is anything other that the 1st (1) it should trigger the validation rule.  But in my system when I use my code or your code it triggers the validation rule if I put in 10/26/2010 but not 9/26/2010 so it is recoginizing the month criteria but for some reason is ignoring the day.

 

Thanks,

Amanda

SporterSporter

Hmmmm try this:

 

 

IF(ISPICKVAL( Category__c , "Winter") && (MONTH(CloseDate)<>12 || DAY(CloseDate) <> 1), true, 
IF(ISPICKVAL( Category__c , "Spring") && (MONTH(CloseDate)<>3 || DAY(CloseDate) <> 1), true, 
IF(ISPICKVAL( Category__c , "Summer") && (MONTH(CloseDate) <> 6 || DAY(CloseDate) <> 1), true, 
IF(ISPICKVAL( Category__c , "Fall") && (MONTH(CloseDate) <> 9 || DAY(CloseDate) <> 1), true, false))))