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
Emma CherringtonEmma Cherrington 

Validation rule with NOT CONTAINS not working

Please can someone help?  

I have no syntax errors on this, but it's also not causing the validation rule to fire when I test it:    

(NOT(contains(text(Picklist_Field__c ), "Text A")))&& (Includes(Multi_Select_Picklist_Field__c , "Text B")).

Interestingly, I started off trying to cover both ways in the same rule:

OR(
((NOT(contains(text(Picklist_Field__c ), "Text A")))&& (Includes(Multi_Select_Picklist_Field__c , "Text B")),
((Contains( Text(Picklist_Field__c ), “Text A”))&&
(NOT(Includes(Multi_Select_Picklist_Field__c , "Text B"))))
)

This works for the second scenario, but not the first, which leads me to think that perhaps 'NOT' doesn't work with 'CONTAINS', but there is no syntax error, it just doesn't work on testing (If I set the picklist field to something other than containing Text A and the multi select picklist field to include a value containing Text B)

Hopefully I'm missing something super obvious?!

TIA

Emma

Best Answer chosen by Emma Cherrington
Emma CherringtonEmma Cherrington

Hi Vinay, thanks, but that was the half of the scenario I'd already got working.  No worries though, I got there in the end.  Paste below for anyone with a similar scenario:

 

(
(ISPICKVAL (Pickval__c , "Value A")) ||
(ISPICKVAL (Pickval__c , "Value B")) ||
(ISPICKVAL (Pickval__c , "Value C"))
&&
(NOT(INCLUDES( Multipickval__c , "Text X")))
)
||
(
(NOT(ISPICKVAL ( Pickval__c , "Value A"))) ||
(NOT(ISPICKVAL (Pickval__c , "Value B"))) ||
(NOT(ISPICKVAL (Pickval__c , "Value C")))
&&
(INCLUDES( Multipickval__c , "Text X"))
)

All Answers

VinayVinay (Salesforce Developers) 
Hi Emma,

Can you elloborate on what are you trying to acheive with above validation rule?  So that we can further check on this?

Thanks,
Emma CherringtonEmma Cherrington
Thanks for the prompt response Vinay.  Its a sort of dependency (it can't be done with dependent fields, I tried, which I assume is due to not being able to use a multi select field as a controlling field?): 
I need to enforce users to only select one of the three values containing Text A in the pick list field, when the multi select pick list field selection(s) include Text B , as well as ensuring that if they select one of those three values containing Text A in the pick list field, that they're only able to select value(s) containing Text B in the multi select pick list field.
I feel like I'm tying myself in knots and making it more complicated than it needs to be?! Lol!

Although it just occured to me that I haven't accounted for someone choosing one of the pick list values containing Text A but then choosing two values in the multi select field, with only one of them containing Text B :-(

Essentially, if the picklist field is any of Value 1, Value 2 or Value 3 (Contains "Value"), the user should only be able to add Item X and/or Item Y in the multi select field (Includes "Item"),not any value that doesn't include "Item".  If the user adds Item X and/or Item Y in the multi select field, they should be prevented from entering anything but the options containing "Value" in the picklist field.

I can't do it by listing the specific values, as it needs to be future proofed for additional values to be added to the multi select field and I don't want to have to update the validation rule every time that happens.
VinayVinay (Salesforce Developers) 
Try below.
 
AND(
OR(ISPICKVAL (piclist__c, "Value 1"),ISPICKVAL (piclist__c, "Value 2"),ISPICKVAL (piclist__c, "Value 3")
),NOT(INCLUDES(multipicklist__c, "Text B"))
)

Thanks,
Emma CherringtonEmma Cherrington

Hi Vinay, thanks, but that was the half of the scenario I'd already got working.  No worries though, I got there in the end.  Paste below for anyone with a similar scenario:

 

(
(ISPICKVAL (Pickval__c , "Value A")) ||
(ISPICKVAL (Pickval__c , "Value B")) ||
(ISPICKVAL (Pickval__c , "Value C"))
&&
(NOT(INCLUDES( Multipickval__c , "Text X")))
)
||
(
(NOT(ISPICKVAL ( Pickval__c , "Value A"))) ||
(NOT(ISPICKVAL (Pickval__c , "Value B"))) ||
(NOT(ISPICKVAL (Pickval__c , "Value C")))
&&
(INCLUDES( Multipickval__c , "Text X"))
)

This was selected as the best answer