I have the below line that compares 2 text fields on a custom object to see if they contain specific values:

 if(Object.Notes__c != null && (Object.Notes__c.contains('Value1') || 

However, now I want to change the statement to see if the text entered in the Notes__c field on my custom object contains any of the values set in CustomSetting1. How would i go about that?

I've tried the following, but I'm not sure if this is right or will give me all the values in my custom setting:

List<Keywords__c> custSet = Keywords__c.Getall().Values();
        string keyWords=custSet[0].Name;

for(Object__c Object : Trigger.New){
     if(Object.Notes__c != null && Object.Notes__c.contains(keyWords))...
  • 3
    What have you tried? Where are you stuck?
    – David Reed
    Nov 9, 2020 at 16:40
  • I updated my post above with what I have tried, but I'm not sure if it's correct.
    – J. Neilan
    Nov 9, 2020 at 17:05
  • No. It compiles without error, but nothing happens on the record. My setting is a list setting with 8 different values. I am trying to compare a text field on a record to see if that field contains any of the values in my custom setting. If so, a checkbox is set to True on the parent record.
    – J. Neilan
    Nov 9, 2020 at 17:17

1 Answer 1


Assuming that the Name field of the custom setting represents the value to be used to check against ...

Map<String,Keywords__c> keywordsByName = Keywords__c.getAll(); // get map
for (Object__c o : Trigger.New) {
    if (keywordsByName.keyset().contains(o.Notes__c)) ... // check set for membership
  • Great, that worked! Thanks so much!
    – J. Neilan
    Nov 9, 2020 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.