Custom metadata rows resemble custom object rows in structure. You create, edit, and delete custom metadata rows in the Metadata API or in Setup. Because the records are metadata, you can migrate them using packages or Metadata API tools. Custom metadata records are read-only in Apex and in the Enterprise and Partner APIs.
Custom Metadata Types are similar to Custom Settings. Let’s see an example to use it in Salesforce.
1. Go to Custom Metadata Types.
2. Click “New Custom Metadata Type”.
3. Save Custom Metadata Type.
4. Click “New” in Custom Fields section.
5. I have created a Field with API name Name__c.
6. Click Manage to create records.
7. Click “New” to create records.
8. Save a test record.
9. To see the records in a VF page use the below code
Visualforce page:
<apex:page controller=”Sample”>
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value=”{!listEmpSettings}” var=”e”>
<apex:column value=”{!e.DeveloperName}”/>
<apex:column value=”{!e.Name__c}”/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Controller:
public class Sample {
public List<Employee_Setting__mdt> listEmpSettings {get;set;}
public Sample() {
listEmpSettings = [SELECT DeveloperName, Name__c FROM Employee_Setting__mdt];
}
}
Output:
Cheers!!!