Sample of Package.xml to deploy Custom Metadata Types

How to Retrieve and Deploy Custom Metadata Types using ANT

Most of you must already know that there is new way to control your program behavior in Salesforce with the help of Custom Metadata Types. Previously we were using List Custom Settings to create functionalities like managing Trigger’s On/Off behavior or controlling Integration endpoint URLs. However we were not able to use Migration tools to import export records into custom settings.

So, into the new world of Custom Metadata Types, I used change sets mostly to perform deployments. Recently, I needed to use ANT migration toolkit to retrieve and deploy Custom Metadata Types. I was able to do it however If you ask me, I spent more time then expected.

Received errors like :

package.xml - Entity type: 'Custom​Metadata' is unknown

Just to make sure not to repeat same mistake and save time in future, lets discuss how we can import / export or rather I will say retrieve and deploy Custom Metadata Types in Salesforce using ANT Migration toolkit.

For the sake of simplicity consider below Custom Metadata Type schema.

Salesforce Custom Metadata Type Schema
Salesforce Custom Metadata Type Schema

Below image shows sample records in Custom Metadata Types

Salesforce Custom Metadata Type Records
Salesforce Custom Metadata Type Records

So the question is, how do we retrieve and deploy above Custom Metadata Types in Salesforce ?

There are two steps to address it

  1. Include Custom Metadata Type schema in package.xml using CustomObject tag
  2. Include Custom Metadata Type records in package.xml using CustomMetadata tag

Sample Source code :




Related Posts


7 responses to “How to Retrieve and Deploy Custom Metadata Types using ANT”

  1. Baird Straughan Avatar

    Thanks Jitendra. You ran into the same issues I had, and you explained them clearly. Note to others:

    In the CustomObject, definition, the Custom Metadata Type takes the __mdt suffix. Like this: Data_Import_Mapping__mdt

    But in the CustomMetaData definition, there are no suffixes, not even on the record names. No __c, for instance. Correct is:


    1. Vandana Avatar

      Thank you Jitendra. And one more point – When u add custom metadata Object to package, it will include all the standard and custom fields. If you have records created under manage options, add those values under custommeta data tag to package. As baird said those values under manage options, will have have any suffixes.

      Thank you @jitendra it was helpful.

  2. Svetlana Vaz Avatar
    Svetlana Vaz

    How do you retrieve all records of a particular custom metadata say ABC__mdt? I tried



    but it just retrieved records from all custom metadata types

    1. Svetlana Vaz Avatar
      Svetlana Vaz

      It retrieves all records with CustomMetadata
      ABD.*, however it also shows an error message : Entity of type ‘CustomMetadata’ named ‘ABC.*’ cannot be found. Any idea why?

      1. Asif Iqbal Avatar
        Asif Iqbal

        i have the same issue

        1. Asif Iqbal Avatar
          Asif Iqbal


          this should be structure to deploy metadata record.
          Earlier i was using
          So the __mdt was causing the issue

  3. Monali Avatar

    I am facing this error while deploying to other dev org from one dev org
    1. objects/Support_Tier__mdt/Support_Tier__mdt.object-meta.xml — Error: Cannot create a new component with the namespace: Support_Tier. Only components in the same namespace as the organization can be created through the API
    2. customMetadata/ — Error: Custom metadata type Support_Tier__mdt is not available in this organization.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading