1

I am trying to refactor our existing Trigger code to more of a Process builder's process. In one of the trigger methods, we are using a List of Custom metadata type records to see if Contact.Name is existed in that list. This works great.

But now that I wanted to implement this same functionality within a Process, I am not sure if this even possible as I have to deal with metadata record comparison. I have referred this Salesforce Official documentation, but it didn't mention a way to use to compare a list of Metadata records to the record id that initiated the Process. Any insights on this would be really helpful.

2 Answers 2

2

You can reference Custom Metadata Types in Process Builder in limited circumstances:

Reference the custom metadata record in Process Builder.
$CustomMetadata.CustomMetadataTypeAPIName.RecordAPIName.FieldAPIName
Use the correct suffixes. For the custom metadata type, use __mdt. For fields, use __c. Records require no suffix. Your formula might look like this one.
[Account].AnnualRevenue > $CustomMetadata.Annual_Revenue__mdt.Annual_Revenue.Minimum_Revenue__c
If the minimum revenue amount changes, edit the custom metadata record rather than your process.

You can't construct these references dynamically, though, to compare a field value to an arbitrary CMT record, or to a list of values from a CMT record. (Your formula in Process Builder will not save if you don't have a valid static reference to a existing Custom Metadata record).

You'd need to go to Flow or Apex to be able to query, build a collection of available values, and check membership of your field value.

3
  • Yeah, I figured the same. I am thinking to reconstruct all the CMT record values into a single CMT record and use a formula with CONTAINS for the comparison purpose. Commented Oct 29, 2019 at 22:07
  • @AustinEvans There's alot of fantastic information in this answer. Your comment has me concerned though. There is a time and a place for PBs and a time and a place for code. If you have to move mountains in order to convert your code into a PB then I would reconsider it. This may be a situation where code makes more sense. Other then that, you should accept Reed's answer, you may decide you dont want to use it but it is technically the correct answer to your question.
    – gNerb
    Commented Oct 29, 2019 at 22:52
  • @AustinEvans - we had a similar issue in our org and we used a trivial FLow that was called by the PB to fetch all CMT and then in a loop, find the matching CMT and apply the relevant action.
    – cropredy
    Commented Oct 29, 2019 at 23:00
0

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;
}

You must log in to answer this question.

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