0

I have something similar to following:

for(CustomMetadataType__mdt config : CustomMetadataType__mdt.getAll().values()){
    //we usually use this to access the field values
    System.debug(config.Field_Name__c);
    //but this seems to work as well!
    System.debug(config.get('Field_Name__c'));
}

Is this a known thing and how come? get() is used both with map (with key) and list (with index). Interested to know about this behavior. Thanks!

1

1 Answer 1

0

I just found out that get() is also one of the methods from SObject class to get the value based on field name! Apologies for not knowing! Ref: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_sobject.htm#apex_System_SObject_get

2
  • 1
    You can also use the get method with a field token, as in config.get(CustomMetadataType__mdt.Field_Name__c);
    – sfdcfox
    Commented Jan 22 at 10:44
  • awesome! yea just saw it in the same ref documentation
    – Borz998
    Commented Jan 22 at 11:07

You must log in to answer this question.

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