Sunday 21 February 2021

Access Custom Metadata Type Records Using Static Methods

Hi,


We were using SOQL query for retrieving "Custom Meta Data Type" Records. 

Now We can Use the Apex getAll(), getInstance(recordId), getInstance(qualifiedApiName), and getInstance(developerName) methods to retrieve information from custom metadata type records faster. These methods don’t rely on the SOQL engine and return the sObject details directly from the call.

The following example uses the getAll() method. The custom metadata type named "EndpointUrlSettings__mdt" has a field called Endpoint__c.

List<EndpointUrlSettings__mdt> endpointUrlList = EndpointUrlSettings__mdt.getall().values();

for(EndpointUrlSettings__mdt endointObj:endpointUrlList){

    System.debug('End point:'+endointObj.Endpoint__c);    

}

System.debug('Record values based on DeveloperName:'+EndpointUrlSettings__mdt.getInstance('Field_Meta_Data'));

Here "Field_Meta_Data" is a developername value of a record in the above Custom Meta Data Type.


Reference:

https://help.salesforce.com/articleView?id=sf.custommetadatatypes_relationships.htm&type=5

https://releasenotes.docs.salesforce.com/en-us/spring21/release-notes/rn_forcecom_dev_static_accessor.htm?edition=&impact=

No comments:

Post a Comment

Best Practices for Building Prompt Templates

 Hi, The following best practices should be considered when building prompt templates: Make sure that your prompt templates are concise and ...