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
Rajesh Singh 88Rajesh Singh 88 

validation rule on date field as per the weekday picklist values

I have the below 2 fields :
Weekdays__c (Multiselect picklist) which contains the values as below :
Monday
Tuesday
Wednesday
Thursday
Friday
ExpirationDate__c (Date) 
My requirement is whenever the picklist values are selected as Monday;Tuesday OR Tuesday;Wednesday;Friday with multiple combinations the date should fall within any of the selected weekdays from the multi-picklist else throw validation.

Example : User selected the Weekday valules as Monday;Tuesday and the selected date is not falling Monday or Tuesday then throw validation. As in the current month Monday is falling on 7, 14, 21 , 28 dates or same in the case of Tuesday so if the user selects date falling on Monday or Tuesday then allow to save the record.

I am a newbie to the sfdc world and I have tried in multiple ways to achieve but couldn't able to. 

For single value I was able to as below but with multiple combinations I wasn't able to do.
AND(INCLUDES(Weekdays__c, "Monday"),
MOD( ExpirationDate__c - DATE(1900, 1, 6), 7) <> 2)
Best Answer chosen by Rajesh Singh 88
AmitSoniAmitSoni
Please try below validation rule:
NOT(
IF( WEEKDAY( ExpirationDate__c) = 2, INCLUDES(Weekdays__c, "Monday"),
IF( WEEKDAY( ExpirationDate__c) = 3, INCLUDES(Weekdays__c, "Tuesday"),
IF( WEEKDAY( ExpirationDate__c) = 4, INCLUDES(Weekdays__c, "Wednesday"),
IF( WEEKDAY( ExpirationDate__c) = 5, INCLUDES(Weekdays__c, "Thursday"),
IF( WEEKDAY( ExpirationDate__c) = 6, INCLUDES(Weekdays__c, "Friday"),false))))))
Hope this will resolve your issue.
 

All Answers

AmitSoniAmitSoni
Please try below validation rule:
NOT(
IF( WEEKDAY( ExpirationDate__c) = 2, INCLUDES(Weekdays__c, "Monday"),
IF( WEEKDAY( ExpirationDate__c) = 3, INCLUDES(Weekdays__c, "Tuesday"),
IF( WEEKDAY( ExpirationDate__c) = 4, INCLUDES(Weekdays__c, "Wednesday"),
IF( WEEKDAY( ExpirationDate__c) = 5, INCLUDES(Weekdays__c, "Thursday"),
IF( WEEKDAY( ExpirationDate__c) = 6, INCLUDES(Weekdays__c, "Friday"),false))))))
Hope this will resolve your issue.
 
This was selected as the best answer
Rajesh Singh 88Rajesh Singh 88
@Amit , Thanks a lot and this really helped me to get the expected result.