You can use a method that retrieves CMT records and use it for the comparison purpose. We had a similar use-case where we need to compare the Case record's owner field to a list of CMT records (which are Queue names, in our case).
Our process builder gets fired when a user (or an automated process) changes Case owner id to a Queue. So our invocable method receives List<Id> caseIds
. Here is a sample code from our class that contains invocable method:
@InvocableMethod
public static void myInvocableMethod(List<Id> caseIds){
//Assigning CMT records to our Map variable
Map<Id, Group> queueMap = getMetadataRecs();
Set<Id> matchedCaseIds = new Set<Id>();
for(Case caseRec: [Select Id, OwnerId From Case Where Id IN : caseIds]){
if(queueMap.containsKey(caseRec.OwnerId)){
matchedCaseIds.add(caseRec.Id);
}
}
if(!matchedCaseIds.isEmpty()){
//Do something
}
}
//Method that retrieves CMT records
public static Map<Id, Group> getMetadataRecs(){
List<String> nameList = new List<String>();
Map<Id, Group> tempMap = new Map<Id, Group>();
List<QueueList__mdt> metaDataRecs = [Select Name__c From QueueList__mdt];
if(!metaDataRecs.isEmpty()){
for(QueueList__mdt rec : metaDataRecs){
nameList.add(rec.Name__c);
}
if(!nameList.isEmpty()){
tempMap = new Map<Id, Group>([Select Name From Group
Where Type = 'Queue' And Name = :nameList]);
}
}
return tempMap;
}