Introduction to Custom Metadata Types

Custom Metadata Types have been available for general access since Summer ’15. Until now, the Salesforce developer community could only create metadata for the types provided by Salesforce. Whether adding custom fields to the account object, creating a custom object or developing an Apex class, one can only configure applications in ways that Salesforce provide out of the box. But with the introduction of Custom Metadata Types, users now have the ability to create their own.

Custom Metadata Types can be used for the following:

  • Mappings – Create associations between different objects, such as custom metadata types that assigns cities, states, or provinces to particular regions in a country.
  • Business rules – Combine configuration records with custom functionality. Use custom metadata types along with some Apex code to route payments to the correct endpoint.
  • Master data – Let’s say that your org uses a standard accounting app. Create a custom metadata type that defines custom charges, like duties and VAT rates. If you include this type as part of an extension package, subscriber orgs can reference the master data.
  • Whitelists – Manage lists, such as approved donors and pre-approved vendors.
  • Secrets – Store information, like API keys, in your protected custom metadata types within a package.

Steps for creating Custom Metadata Type

1. Define a Custom Metadata Type Declaratively:

Search Setup for Custom Metadata Types.

On the All Custom Metadata Types page, click New Custom Metadata Type, or click the Label name to modify an existing custom metadata type.

Complete these fields.

2. Add or Edit Custom Metadata Records Declaratively

Search Setup for Custom Metadata Types.

On the All Custom Metadata Types page, click Manage Records next to the custom metadata type for which you want to add or modify records.

On the list of custom metadata records, click New, or click Edit to modify an existing custom metadata record.

Fill out the fields. The Protected Component checkbox determines whether the record is protected. A protected record is only accessible to code in the same namespace as either the record or its associated custom metadata type: the code you create, code in an unmanaged package, and code in the same managed package as either the protected record or its custom metadata type.

Click Save.

Advantages of Custom Metadata Types over Custom Settings

1. Supports complex data types for custom fields creation and storing information.

  • Metadata Relationship
  • Checkbox
  • Date and Date/Time
  • Email and Phone
  • Number
  • Percent
  • Picklist
  • Text and Text Area
  • URL

2. The custom metadata records can also be deployed along with the metadata type definition via changesets or force.com migration tool (ANT). In custom settings the records are uploaded after deployment of the Custom setting definition. Sample XML file for the Metadata Type deployment is given below:

 

<Package xmlns=”http://soap.sforce.com/2006/04/metadata”>
    <types>
        <members>App_Configuration.Disable_Trigger</members>
        <members>App_Configuration.Disable_Trigger_IDs </members>
        <name>CustomMetadata</name>
    </types>
    <types>
        <members>App_Configuration__mdt</members>
        <name>CustomObject</name>
    </types>
    <version>39.0</version>
</Package>

 

  1. For editing the Custom Metadata records user should have “Configure Application” and for edit the configuration “Author Apex” permission is required. Admins can now control who can edit the records vs the definition.

  2. List Views, Page Layouts and Validation Rules can be created on the Custom Metadata Types.

Limitations of using Custom Metadata:

  1. Cannot be updated using Apex. The only way to edit custom metadata types is by leveraging metadata API.
  2. 100 custom metadata types can be created per salesforce org.
  3. 100 custom fields can be created per Custom Metadata Type object.

Subscribe To The Monthly Newsletter

No Spam. No Rubbish. Just great content from the Salesforce Industry.

You have Successfully Subscribed!

6 thoughts on “Introduction to Custom Metadata Types

  1. Avatar

    I think you left out something very important. How do I get “Country” and “VAT Charges” to show up? When I click Manage Records, I only see “Label” and “VAT Charges Name”. There is a step missing to produce the same output you show.

  2. Avatar

    Very beautifully explained. Waiting for a release when we will be able to use DML operations on custom metadata types.

Leave a Reply