custom metadata types

Custom Metadata Types for Admins

Custom Metadata Types are a very powerful capability in the Salesforce platform, but many people don’t know what it is, or how to use it. I wanted to give some background and examples to help admins understand how it could be used in their orgs.

What are Custom Metadata Types?

Custom Metadata Types are similar to Custom Settings in Salesforce, except that they are deployable and packagable. The architecture consists of the metadata type, and custom records defined by the type. This means they are similar to a simple custom object. You create custom fields to match the needs of your business case. Then individual records can represent the necessary data.

Use Cases

Master Data Management – You can use Custom Metadata Types to store master data records to be used throughout an organization. Some common use cases I have seen are storing org-wide VAT or tax calculations, and partner tier thresholds. In the case of tax calculations, relationships between country and state are created to store individual tax rates. Apex code or formula fields can access the metadata records to perform the calculations.

Business Processes – Validation or routing of records is handled by specific business logic, and needs to be controlled org-wide.

Protected Information – Store data like API keys in a protected package.

Relationship Mapping – Control relationships like assigning a state or zip to a territory.

Creation and Management

To create a Custom Metadata Type, navigate through Setup and click New. Similar to the creation of a custom object, you are prompted to add a name and plural name, API name, description and visibility. From there, you can create the custom fields required to meet your use case.

Adding and editing records is handled declaratively by clicking ‘Manage Records’. Custom Metadata Types can also have relationships by creating a EntityDefinition.

Accessing Metadata Records

There are several ways to use the data in a Metadata record. For developers, Apex can access the data as long as the metadata records are visible in the code’s namespace. The syntax looks like this:

MyCustomMetadataType__mdt custMeta;

Queries can be run and the returned data can be used for calculations, decisions, etc.

For admins, the metadata records can be accessed via validation rules, formula fields and flows.

Real World Example

Here is a real example of how I have used Custom Metadata Types to solve a client problem.

A company sells through a channel, and their partners are ranked based on sales volume. The sales thresholds are geographically unique, and need to be updated a few times per year. A metadata type was created for holding this information. The Partner_Tier__mdt type was created, and fields were added for Bronze Tier, Silver Tier, Gold Tier, and Platinum Tier. This contained the threshold, associated pricebook, and certified employees for each tier.

Once created, metadata records were created for the individual territories (US, Canada, UK, etc.). On the Account object, custom fields were created.

  • Partner Tier Reference – Picklist containing location (US Partner, UK Partner, etc.). This maps to the metadata record that will be used for calculation.
  • Partner Tier – Formula field to compare sales to thresholds in metadata record. In this case, I use CASE syntax with the following metadata reference:
    ($CustomMetadata.Partner_Tier__mdt.Domestic_Partner_2019.Bronze_Tier__c)
  • Sales to Next Tier – Formula subtracting current sales from next tier using CASE statement.

A trigger is used to assign the pricebook to all opportunities based on the partner’s tier. The benefits to this setup is that all partner tier calculations happen automatically when the corresponding tier metadata record is updated. The company can work on a new set of tier records in a sandbox and deploy to production when ready.

Custom Metadata Types are an interesting option to solve problems. If you are unfamiliar with them, I recommend doing this Trailhead for some background. If you have an interesting use case, feel free to share in the comments below.

I am a 22x Salesforce certified consultant, currently working for the implementation partner Simplus. I am passionate about Salesforce, and I enjoy the friendly ecosystem that is filled with talented, intelligent professionals.
Posts created 36

One thought on “Custom Metadata Types for Admins

  1. The advantage to your blogs over others is your explanations using real world examples and use cases. Well done, sir! Very interesting feature that I was not aware of that many ISV developers should also consider.

Leave a Reply

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

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top