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
John Neilan 18John Neilan 18 

Check for Custom Setting Values in Text Field

I am trying to figure out a way that I can look at the value of a text field and check it to see if any part of the text contains values that are entries in a Custom Setting. I tried the following to set up my Custom Setting list of words:  
List<Keywords__c> listKeywords = [SELECT Name FROM Keywords__c];
 
Set<String> kw = new Set<String>;
Then within a loop of my custom object, I am trying to check if any part of the text field is one of the words in the list above:

   
for(Object__c = object:Trigger.new){
    IF(kw.contains(object.Notes__c){
        object.Impact__c = TRUE;
    }else{
        object.Impact__c = FALSE;
    }
}

The problem with this is that it checks the entire value of the Notes__c field against the list and does not just look for any part of Notes__c that is contained in the list.  For example, if "Test" is in my custom setting, the code above works if the Notes__c field is "Test" but it does not work if the Notes__c field is "Test Test". Can anyone help with the proper code to get this to work?
Maharajan CMaharajan C
Hi John,

I think there is no straightway for this. You can use the one more for loop to this. Because contains in list or set class checking the exact element is there or not. I hope your custom won't have much data.
 
for(Object__c = object:Trigger.new){
	for(String str : kw){
		IF(str.containsIgnoreCase(object.Notes__c){
		object.Impact__c = TRUE;
		}else{
			object.Impact__c = FALSE;
		}
	}
}


Thanks,
Maharajan.C