I have a requirement in which I have a field on Case object named random__c and it is a text field and also there is another field on Case object named value__c.

So my requirement is that if the random__c field contains certain keyword like "help", "urgent",etc. then I want to update the value __c field with some data.

Now there is no limit to the keywords and unlimited keyword could be added in the coming future for which the value __c needs to be updated.

I know one way to handle this is to check for the keywords in the code using OR condition one by one and every time a new keyword will be added then I'll have to update the code with and extra OR condition for the new keyword. So I was thinking if I can create a Custom Label and keep the keywords in there separated with "," (Comma) and then call this Custom Label into the code and check for the keywords presence in the random__c field and in this way I'll have to add the keywords in the custom label only and not have to make changes in the code.

Is there a way this can be achieved? Can anyone please give me a sample code to achieve this? Please guide.

Thanks in advance !

1 Answer 1


If you know how you're going to store it, you can leverage split on the label and some form of contains for List and String. Below assumes random__c would be exactly the same string as something in your list of possible values.

//split your label into a list of strings
List<String> keywordChecklist = System.Label.Comma_Separated_Keywords.split(',');
//now you can leverage contains instead of any hard-coded or long winded OR statements
    //do whatever needs to be done

If you need to check if the random__c field contains any word from a list and it wouldn't be an exact match - it'd be something similar except you'd have to loop through the values

Boolean found = false;
List<String> keywordChecklist = System.Label.Comma_Separated_Keywords.split(',');

for(String keyword : keywordChecklist){
        found = true;

Either way, I'd stress the importance of adding a description to your custom label to state the expected format as any edits to the label could mess up your logic and helps the next person understand why the label exists

You mentioned unlimited keywords - just be aware a label would have a limit of 1,000 characters. If a label doesn't work out due to that requirement, a custom metadata type would serve you well. The only thing that changes is how you get your keyword list

List<Keyword_Checklist__mdt> keywordChecklist = Keyword_Checlist__mdt.getAll().values();

for(Keyword_Checklist__mdt keyword : keywordChecklist){
        found = true;

The benefit of the custom metadata type is that it allows for greater extension in the future if you ever need to have different keyword checklists depending on something on the case (ex. record type) since you can add other custom fields and have more information

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.