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
Coral RacingCoral Racing 

(Not (Contains ) Validation Rule not working as expected

Hello,
I have the following validation rule that doesn't seem to be working as expected as it is firing an email when it is not true.  is there an error somewhere?

(OR(

(CONTAINS(BMCServiceDesk__Client_Name__c, "1") = False),

(CONTAINS(BMCServiceDesk__Client_Name__c, "2") = False),

(CONTAINS(BMCServiceDesk__Client_Name__c, "3") = False),

(CONTAINS(BMCServiceDesk__Client_Name__c, "4") = False),

(CONTAINS(BMCServiceDesk__Client_Name__c, "8") = False),

(CONTAINS(BMCServiceDesk__Client_Name__c, "9") = False)

))



Thanks

Sonya
Best Answer chosen by Coral Racing
Muralidhar S (Salesforce)Muralidhar S (Salesforce)
I am assuming the line (BMCServiceDesk__TemplateName__c 'Pin Request') means CONTAINS(BMCServiceDesk__TemplateName__c, 'Pin Request'). Please try this. I recommend to put this into a formula field for the corresponding object and check with the report what is the result. It would be easier that way to debug the formula. Thanks

 NOT(
  OR(
   CONTAINS(BMCServiceDesk__Client_Name__c, "1"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "2"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "3"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "4"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "8"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "9")
   (BMCServiceDesk__state__c = True),
   (ISBLANK( BMCServiceDesk__FKRequestDetail__c) ),
   CONTAINS($Profile.Name, "Trading"),
   CONTAINS(BMCServiceDesk__TemplateName__c, 'Pin Request'),
   CONTAINS(BMCServiceDesk__Client_Name__c, 'GCSD Supervisors')
  )
 )

All Answers

Muralidhar S (Salesforce)Muralidhar S (Salesforce)
Sonya,
Remove the '=False' assignments because CONTAINS(text, compare_text) checks if text contains specified characters, and returns TRUE if it does. Otherwise, returns FALSE. So OR-ing multiple CONTAINS statement will be TRUE if any one of the CONTAINS is TRUE. Hope I am clear. Thanks
Coral RacingCoral Racing
Hi I ahve removed the = false and replace with Not (Contains) but it still doesn't work.
What do you mean by 'OR-ing multiple CONTAINS statement will be TRUE if any one of the CONTAINS is TRUE'
Is there a way to write this so when this criteria is met, the email will not be fired ?

Thanks

Sonya
Coral RacingCoral Racing
I have also tried Not(Begins) to no availa as well.

Thanks

Sonya
Muralidhar S (Salesforce)Muralidhar S (Salesforce)
For Brevity I have cut it short. The below first statement will be True if either BMCServiceDesk__Client_Name__c contains "1" OR contains "2". So if you do not want to fire an email in case any one of the assertion is true, then you can wrap the below statement into IF as shown therafter:

OR(CONTAINS(BMCServiceDesk__Client_Name__c, "1") ,(CONTAINS(BMCServiceDesk__Client_Name__c, "2"))

IF(OR(CONTAINS(BMCServiceDesk__Client_Name__c, "1") ,(CONTAINS(BMCServiceDesk__Client_Name__c, "2")) , false, true).

And in case if it is the reverse, i.e. fire an email if any one of the "Contains" assertion is true then no need of wrapping the OR statement. If still not working, then just let me know in words the requirement as to when the email should to be triggered and sample values of BMCServiceDesk__Client_Name__c. Would be happy to help. Thanks
Coral RacingCoral Racing
Hello Thanks for the help. Sorry I am very confused. Below is my whole validation rule. I am not sure how to nest IF statements as will need 3 as I do not want an email to fire if any of them are true? (OR( (CONTAINS(BMCServiceDesk__Client_Name__c, "1") = False), (CONTAINS(BMCServiceDesk__Client_Name__c, "2") = False), (CONTAINS(BMCServiceDesk__Client_Name__c, "3") = False), (CONTAINS(BMCServiceDesk__Client_Name__c, "4") = False), (CONTAINS(BMCServiceDesk__Client_Name__c, "8") = False), (CONTAINS(BMCServiceDesk__Client_Name__c, "9") = False) )) &&(BMCServiceDesk__state__c = True) && (ISBLANK( BMCServiceDesk__FKRequestDetail__c) )&& (CONTAINS($Profile.Name, "Trading") = False)&& (OR(BMCServiceDesk__TemplateName__c 'Pin Request'))&& (OR(BMCServiceDesk__Client_Name__c 'GCSD Supervisors')) Thanks Sonya
Coral RacingCoral Racing
Sample Client Name would be e.g. Crawley 2549,   London 1773,  Joe Bloggs
Coral RacingCoral Racing
And the requirement is if the Client name contains, 1,2,3,4,8,9 that the email doesn't fire but otherwise it will :)
 
Muralidhar S (Salesforce)Muralidhar S (Salesforce)
I am assuming the line (BMCServiceDesk__TemplateName__c 'Pin Request') means CONTAINS(BMCServiceDesk__TemplateName__c, 'Pin Request'). Please try this. I recommend to put this into a formula field for the corresponding object and check with the report what is the result. It would be easier that way to debug the formula. Thanks

 NOT(
  OR(
   CONTAINS(BMCServiceDesk__Client_Name__c, "1"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "2"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "3"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "4"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "8"),
   CONTAINS(BMCServiceDesk__Client_Name__c, "9")
   (BMCServiceDesk__state__c = True),
   (ISBLANK( BMCServiceDesk__FKRequestDetail__c) ),
   CONTAINS($Profile.Name, "Trading"),
   CONTAINS(BMCServiceDesk__TemplateName__c, 'Pin Request'),
   CONTAINS(BMCServiceDesk__Client_Name__c, 'GCSD Supervisors')
  )
 )
This was selected as the best answer
Coral RacingCoral Racing
Thanks for this, this works great now.  Sonya