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
Newbie10Newbie10 

Profanity check

I have a multiselect picklist in my grandparent object.

I have a text field in my object.

Whenever user enters text into this text field ,and after saving i need to check whether my text contains the values defined in picklist


This is mainly for a profanity check .

what is the best way to do this?

souvik9086souvik9086

Do like this

 

trigger ProfanityCheck on Object__c(after insert,after update){

Set<String> pkVals = new List<Set>();
for(Object__c obj : Trigger.new){
String selObj = 'Object__c';
Schema.DescribeFieldResult pkField = selObj.getDescribe().fields.getMap().get(obj.FatherParent__r.GrandParent__r.PicklistField__c).getDescribe();
List<Schema.PicklistEntry> pkValues = urlParamType .getPicklistValues();
for(Schema.PicklistEntry p : pkValues ){
pkVals.add(p.getValue());
}
if(pkVals.contains(p.TextField__c)){
//Write what you want to do if that condition satisfies
}
}
}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Satish_SFDCSatish_SFDC
Or you can also write a validation rule to check if the text contains any of the picklist values.

Regards,
Satish Kumar
Newbie10Newbie10
Can you please write the exact formula how we do that.
A multipicklist where values are defined

and a text fields where i need to check whether any of the content contains any of these values in picklist
Satish_SFDCSatish_SFDC
IF(Contains(SampleText__c,IF(INCLUDES( Parent__c.Profanity_Picklist__c ,"Xyz"),"Xyz","")),true,false) 
|| 
IF(Contains(SampleText__c,IF(INCLUDES(Parent__c.Profanity_Picklist__c,"ABC"),"ABC","")),true,false)

 

The values are case sensitive i believe.

 

If there are a lot of values in the picklist, its best to use a trigger as one of our members suggested.

 

Hope this helps. 

 

Regards,
Satish Kumar
Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.