I have custom metadata records in the format:

enter image description here

If I store these Key and Values in a Map, how to have a conditional 'contains' check for the auxiliary word: Apartment_1

Use-case: I will need to compare the auxiliary value that is being passed by the user to my search. So, whenever my temporary search value contains the word: Apartment_1, I should be able to check if my map contains a key that matches part of the that temporary search value. And if yes, I should also compare the value of this key to another string coming as an another input.


Inputted temporary search key variable: Apartment_1

Inputted temporary search value variable: WindowLess

Scenario #1: Map contains Apartment_1 as a key == TRUE, but value == Window (which is not equal to WindowLess).


Scenario #2: Map contains Apartment_1 as a key == TRUE, value == Windowless


My implementation without using a Map for the values:

//Retrieving from CMD
List<String> auxiliaryList = new List<String>();
List<CustomMetadata__mdt> myCMDRecords = 
        [Select Id, Auixliary__c, Value__c From CustomMetadata__mdt];

if(!myCMDRecords .isEmpty( )) {

valueDevNames = new Set<String>(); 
 for(CustomMetadata__mdt rec : myCMDRecords ){

//Creating a map of Queues
                queueMap = new Map<Id, Group>([Select Id, Name From Group 
                                               Where Type = 'Queue' And Name = :auxiliaryList]);

//Implementation logic
Set<Id> caseIdSet = new Set<Id>();
if(!queueMap.isEmpty() && !valueDevNames.isEmpty()){
 for(Case caseRec: [Select Id, OwnerId, RecordType.DeveloperName From Case Where Id IN : passedCaseIds]){
          if(queueMap.containsKey(caseRec.OwnerId) && valueDevNames.contains(caseRec.RecordType.DeveloperName)){
  • do you have any code you've attempted? You basically wrote out the steps. Query all custom metadata records, utilize maps and for loops, and do some if else checks . Commented Dec 16, 2019 at 20:14
  • Yes, currently I am using a Set variable to store the above values. And I am checking if the inputted Value exists in the provided Set. I will post my code soon. Commented Dec 16, 2019 at 20:18
  • What is the question here? Commented Dec 16, 2019 at 21:12
  • @ZachHutchins If I store the Key and Values in a Map (from above screenshot), how to have a conditional 'contains' check for an inputted string within the Keys? Commented Dec 16, 2019 at 21:15
  • @AustinEvans From where are you getting the Key? is it stored on the Mdt record?
    – samdev
    Commented Dec 16, 2019 at 21:15

1 Answer 1


Is this what you are talking about?

private List<Map<string,object>> MapKeysContain(Map<string,object> map, string comparer){
    Set<string> keys = map.keySet();
    Map<string,object> m_subsetMap = new Map<string,object>();
    for(string k : keys)
            m_subSetMap.put(key, map.get(k));
    // Just here for example, can do a lot with this like map.size() > 0
    return m_subSetMap;


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .