ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Using Custom Metadata Type in Salesforce

Home / Article & Blogs / Uncategorized / Using Custom Metadata Type in Salesforce
By Nitish inUncategorized

Custom Metadata Types have great and valuable features which makes it very useful package-able component. It can be used as custom setting  and can be deployed as any other metatdata type.

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 (that’s the only limitation which I feel makes where you might need to choose Custom setting over custom metadata type).

The biggest advantage Custom metadata type gives is it does not count into SOQL queries for each Apex transaction.You can go through the details of Custom Metadata Type in Salesforce Documentation (https://help.salesforce.com/HTViewHelpDoc?id=custommetadatatypes_overview.htm). You can also go through the implementation guide of Custom Metadata Type (http://resources.docs.salesforce.com/200/9/en-us/sfdc/pdf/custom_metadata_types_impl_guide.pdf).

In this article I will try to explain how we can get the country names based on the country codes in visualforce pages. A very common scenarios where developers generally use list type Custom Setting to store the mapping of Country Codes and Country Names.

We will create a Custom Metadata Type called CountrySetting with a custom field called Country Name. Attached Screenshot is the configuration of the Custom Metadata Type.The Custom Metadata Type has a suffix of __mdt instead of __c (for Custom objects/fields). We can also create a picklist field in custom metadata type (Currently this is in beta phase and hopefully will be available globally soon) .

Screen Shot 2016-02-23 at 9.20.46 pm

Lets create some data so that it displays in our Visualforce page. You can click on Manage button and click on New to create the records (Similar to creating records in Custom setting).

Screen Shot 2016-02-23 at 10.04.15 pm

Next step is to build Visualforce page which shows the Country Codes and Country Names and the controller required to build that.

I have created an apex class which has a method which returns a list of custom metadata types.

[sourcecode language=”java”]
public with sharing class CountrySettingController {
public list<CountySetting__mdt> getCountrySetting(){
return [Select DeveloperName,MasterLabel, Country_Name__c from CountySetting__mdt];
}
}
[/sourcecode]

Now lets create the Visualforce page.

[sourcecode language=”java”]&lt;/pre&gt;
&lt;pre class=&quot;codeBlock&quot;&gt;&lt;apex:page controller=&quot;CountrySettingController&quot;&gt;
&lt;apex:sectionHeader title=&quot;Custom Settings&quot; subtitle=&quot;List Demo&quot;/&gt;
&lt;apex:form &gt;
&lt;apex:pageBlock &gt;
&lt;apex:pageBlockTable value=&quot;{!CountrySetting}&quot; var=&quot;item&quot;&gt;
&lt;apex:column value=&quot;{!item.MasterLabel}&quot;/&gt;
&lt;apex:column value=&quot;{!item.DeveloperName}&quot;/&gt;
&lt;apex:column value=&quot;{!item.Country_Name__c}&quot;/&gt;
&lt;/apex:pageBlockTable&gt;
&lt;/apex:pageBlock&gt;
&lt;/apex:form&gt;
&lt;/apex:page&gt;
[/sourcecode]

Here is the attached screenshot of the Visualforce page

Screen Shot 2016-02-23 at 10.19.35 pm

If you check the log files , you can see that the method which queries the Custom metadata type does not count towards the SOQL Limit. This was a basic example which shows how we can use Custom metadata type in apex.Since custom metadata types are metadata rather than data, they leverage all the tools Force.com already has for managing, packaging and deploying metadata. This makes them very useful if you are building package-able apps.

104
Like this post
2 Posts
Nitish

Search Posts

Archives

Categories

Recent posts

BioAsia 2023 in Hyderabad: An Annual International Event

BioAsia 2023 in Hyderabad: An Annual International Event

The Role Of Marketing in Small & Medium Enterprises

The Role Of Marketing in Small & Medium Enterprises

Salesforce For Retail: How Salesforce CRM Can Help Retailers

Salesforce For Retail: How Salesforce CRM Can Help Retailers

What is ChatGPT & How Does It Work?

What is ChatGPT & How Does It Work?

What Is Graphic Design? (Executive Summary 2023)

What Is Graphic Design? (Executive Summary 2023)

  • Previous PostWhat is files connect ? And why should we care about it ?
  • Next PostConnect Salesforce with Microsoft office

Related Posts

HOW THE TALENTS ARE TRAINED AT ABSYZ
Uncategorized

HOW THE TALENTS ARE TRAINED AT ABSYZ

Why choose Salesforce Integration Partners?
Salesforce Implementation Uncategorized

Why choose Salesforce Integration Partners?

2 Comments

  1. E.L. Cropredy
    Reply
    14 June 2016

    This is interesting but the feature seems to be missing something … to wit:

    How do you validate that the rows of custom metadata pass your “business rules”. There are no VRs on __mdt, you can’t write triggers on __mdt, and the only thing I could think of was to create a bespoke VF page whose controller did validation in APEX before saving the rows via the APEX metadata API wrapper.

    Using your example, verifying no duplicates; verifying that country codes were two character alpha; verifying that two country codes don’t map to the same country name, etc.

    Reply
    • Nitish
      Reply
      15 June 2016

      Yes you are right but the idea of using custom metadata type is to use for packaging. That way you can send the records as part of the package. Custom Setting had that limitation and Custom Metadata type overcomes that

      Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT