Setup a consultation
Recent Posts
While deploying any functionality or application to another org either by using change sets or packages we can deploy only Meta data like Custom Objects, Apex Classes, Visualforce Pages and Custom Settings but the record data like instances of Custom Objects and Custom Settings cannot be included.
After installing the package we need to also undertake some post install activities like configuring master data for the application.
By using Custom Metadata Types we can migrate configuration data (records) from one org to another org very easily at the time of deployment by using packages or Metadata API tools. It will definitely reduce the amount of effort required to populate records required by an application.
Custom Metadata Types are similar to our salesforce objects or custom settings.
o Checkbox
o Date
o Date and Time
o Email
o Number
o Percent
o Phone
o Picklist
o Text
o Text Area
o URL
It has a list of custom fields to hold Meta data records in addition to records which object and custom settings are holding.
The Custom Metadata records can be enquired about just like normal records using SOQL and it does not count into SOQL queries for each Apex transaction.
The Custom Metadata Type has a suffix of __mdt instead of __c (for Custom objects/fields).
Here I will try to explain how we can get the country names based on the country codes in visualforce pages. Below is the scenario where every developer generally uses list type Custom Setting to store the mapping of Country Codes and Country Names.
Develop ->Custom Metadata Types -> New Custom Metadata Type
• Public—anyone can see it.
• Protected—if the type is installed as part of a managed package, only Apex code in that managed
package can use it
Create a field called Country Name of type Text
Let us create some data so that it displays in our Visualforce page. You can click on Manage button and further click on New to create the records (Similar to creating records in Custom setting).
Next step is to build a Visualforce page which shows the Country Codes and Country Names and the controller required to build that.
public with sharing class MetaDatatypeDemoCC {
public list<Country_Settings__mdt>getCountrySetting(){
return [Select DeveloperName,MasterLabel, Country_Name__c from Country_Settings__mdt];
}
}
<apex:page controller="MetaDatatypeDemoCC">
<apex:pageblock>
<apex:pageblockTable value="{!CountrySettings}" var="country">
<apex:column value="{!country.MasterLabel}"/>
<apex:column value="{!country.DeveloperName}"/>
<apex:column value="{!country.Country_Name__c}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:page>Here is the screenshot of the Visualforce page
By checking log files the method which queries the Custom Metadata Type does not count towards the governor limits. Since custom metadata types are metadata rather than data, they leverage all the tools Force.com already has for managing, packaging and deploying metadata. It is extremely useful if you are building package-able apps.