1

I query over Custom metadata to get 1 record(settings) with custom fields "MdtFieldsAcc" I pass the fields in a map with .getPopulatedFieldsAsMap() and then currently remove 1 keyset (Id). Is there a method or way to only maintain keysets that start with a certain string?.

For example if my Custom metadata has the following fields:

 Account_Sold_to_CRM_Contact__c, 
                Account_Bill_to_CRM_Contact__c, 
                Account_Payment_Gateway_Id__c, 
                Account_Payment_Method_Token__c,

                Contact_Gender__c,
                Contact_Initials__c,

                Adr_Billing_Housenumber__c,
                Adr_Billing_Housenumber_Ext__c,
                Adr_Billing_Country_Lookup__c,
                Adr_Shipping_Housenumber__c,
                Adr_Shipping_Housenumber_Ext__c,
                Adr_Shipping_Country_Lookup__c, 

Filter only on fields starting with Adr_?

Something like:

keySet().Contain('Adr_')

Apex

Map<String, Object> populateFieldsMap = MdtFieldsAcc.getPopulatedFieldsAsMap(); 
      populateFieldsMap.keySet().remove('Id'); // Id field is queried by default 
      xFieldsAcc += '#' + String.join(populateFieldsMap.values(), '#');
1
  • 1
    Nope. Gonna have to roll your own.
    – Adrian Larson
    Dec 10, 2019 at 6:15

1 Answer 1

2

I don't know of anything out-of-the-box Apex that will do that kind of filtering.

A sample helper method in Apex would look like this:

public Set<String> filterStartsWith(Set<String> fields, String filter) {
    Set<String> filtered = new Set<String>();

    for (String field : fields)
        if (field.startsWith(filter)) 
            filtered.add(field);

    return filtered;
}

You must log in to answer this question.

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