function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lavaralavara 

Access Custom Metadata Types through Visualforce

How do we access Custom Metadata Types through Visualforce? I couldn't find any relevant article that covers this to the point. I have a requirement, where I need to reference the custom MDT and populate variable values in the VF page based on the MDT value. Have read that we could use remote objects to do that. Any help on that would be appreciated.
PS: We are not using any custom controllers for this VF page.
KumarRajaBangari14KumarRajaBangari14
Hi Iavara,

I think the data in Custom Metadata Types can be accessed only by SOQL. Since you are not using custom controller, use Ajax to run the query to access the data. Something like below.
sforce.connection.query("Select Id From VF_Page_Setup__mdt limit 10", callback);
Follow the link below to know more about querying in vf using Ajax.
https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_vf_sample.htm (https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_vf_sample.htm" target="_parent)

Custom Metadata Types - Guide
https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_custommetadatatypes.htm (https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_vf_sample.htm" target="_parent)

Custom Metadata Types Implementation Guide.
https://resources.docs.salesforce.com/218/latest/en-us/sfdc/pdf/custom_metadata_types_impl_guide.pdf

If your question was about $Setup.[customSetting].[field], it is only used when referencing a custom setting of type “hierarchy” and not for custom metadata types.

Comments or corrections are appreciated.

Regards,
Kumar