---
schema_version: "1"
id: e6e99f92bb2c01287aae49b53e06f74658bf7f7a6bc0fd4d9a18616ccf028594
title: Create and Manage Custom Metadata Types Using CLI Commands
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/custommetadatatypes_cli.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.custommetadatatypes_cli.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 08be5b432aefdf78befaeaade04c0fd1056710bdcf5e06d920f4aeec5d655b43
description: You can use the Salesforce command-line interface (CLI) to create custom metadata types, generate fields, create records, create records from a CSV file, and generate custom metadata types from an sObject.
products:
  - Salesforce Platform
release: "264"
---
# Create and Manage Custom Metadata Types Using CLI Commands

You can use the Salesforce command-line interface (CLI) to create custom metadata types, generate fields, create records, create records from a CSV file, and generate custom metadata types from an sObject.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition">
      <colgroup>
        <col>
      </colgroup>
      <tbody>
        <tr class="">
          <td class="slds-cell-wrap" style="vertical-align:top;">Available in: Salesforce Classic and Lightning Experience</td>

        </tr>
        <tr class="">
          <td class="slds-cell-wrap" style="vertical-align:top;">
            <p>Available in: <strong>Enterprise</strong>, <strong>Performance</strong>, <strong>Unlimited</strong>, and
              <strong>Developer</strong> Editions
            </p>
            <p style="margin-bottom:0;">You can create, edit, and delete custom metadata type records
              from installed packages in: <strong>Group</strong> and <strong>Professional</strong> Editions</p>
          </td>

        </tr>
      </tbody>
    </table> <table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small permission">
      <colgroup>
        <col style="width:50%">
        <col style="width:50%">
      </colgroup>
      <thead class="slds-text-title_caps ">
        <tr class="">
          <th scope="colgroup" class="slds-cell-wrap" colspan="2" style="text-align:center;vertical-align:top;" id="d24460e78">User Permissions Needed</th>
        </tr>
      </thead>
      <tbody>
        <tr class="">
          <td data-label="User Permissions Needed" class="slds-cell-wrap" style="vertical-align:top;" headers="d24460e78 ">To run custom metadata types CLI commands:</td>

          <td class="slds-cell-wrap" style="vertical-align:top;" headers="d24460e78 ">Customize Application</td>

        </tr>
      </tbody>
    </table>

Support for custom metadata types is available in the [Salesforce CLI](https://developer.salesforce.com/tools/salesforcecli) plugin version 49.0. See the Salesforce CLI Setup Guide for information about how to set up CLI, set up a developer hub, create a project, and create a scratch org.

## Commands

The following commands are available to create and manage custom metadata types. For flags and usage information, use the `--help` flag. For example, `sf cmdt generate records --help`.

- Create a custom metadata type.
    
    `sf cmdt generate object`
- Generate a custom metadata field based on the specified field type. You can create fields within the metadata object folder or passed in the directory of the object folder.
    
    `sf cmdt generate field`
- Generate a custom metadata type and all its records for an sObject. Use this command to migrate existing custom objects or custom settings to custom metadata types. The default directory is `force-app/main/default/customMetadata`.
    
    `sf cmdt generate fromorg`
    
    ![Note](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_note.png)
    
    Note Custom Settings of type hierarchy are not supported.
- Create a record for a specified custom metadata type.
    
    `sf cmdt generate record`
- Insert new custom metadata type records from a CSV file.
    
    `sf cmdt generate records`

## Considerations

- Specify the object folder when creating custom metadata types or fields. For example, `--output-directory force-app/main/dirObjects/Mycmdt`.
- Specify unique names when creating custom metadata types.
- There are no restrictions on the number of records that can be inserted. When inserting a large number of records, be aware that the `project deploy start` command defaults to 33 minutes. The default is the number of minutes the command waits to complete and display results to the terminal window.
- When using the `cmdt generate records` command, the `DeveloperName` identifier defaults to the column `Name` and is a required column. However, any column name can be specified by using the `--name-column` flag. `Label` is not supported as an alternative identifier.
- The `cmdt generate records` command can be used to create new custom metadata types records or update existing custom metadata records.

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_example.png)

Example Create a custom metadata type that is protected along with the field types percent and checkbox. The metadata XML is created in the local directory for your SDFX project.

```
sf cmdt generate object --type-name Mycmdt --visibility Protected --output-directory force-app/main/dirObjects
sf cmdt generate field --name Checkbox --type Checkbox --output-directory force-app/main/dirObjects/Mycmdt
sf cmdt generate field --name Percent --type Percent --output-directory force-app/main/dirObjects/Mycmdt
```

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_example.png)

Example Generate a custom metadata type from a custom object. Use this command to migrate an existing custom object to a new custom metadata type.

```
sf cmdt generate fromorg --dev-name FromCustomObject --sobject MyCustomObject__c
```

![Example](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-platform-extend_code-264-0-0-production-enus/789bc523-706b-4ae4-8fe9-be6322e38b6b/images/icon_example.png)

Example Insert records into an existing custom metadata type from a CSV file.

Create a CSV file and provide the API name of the custom metadata type in the insert command. For example,

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small "><colgroup><col style="width:33.33333333333333%"> <col style="width:33.33333333333333%"> <col style="width:33.33333333333333%"></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><strong>Name</strong></td><td class="slds-cell-wrap" style="vertical-align:top;"><strong>CountryCode__c</strong></td><td class="slds-cell-wrap" style="vertical-align:top;"><strong>CountryName__c</strong></td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Australia</td><td class="slds-cell-wrap" style="vertical-align:top;">AU</td><td class="slds-cell-wrap" style="vertical-align:top;">Australia</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Brazil</td><td class="slds-cell-wrap" style="vertical-align:top;">BZ</td><td class="slds-cell-wrap" style="vertical-align:top;">Brazil</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Canada</td><td class="slds-cell-wrap" style="vertical-align:top;">CA</td><td class="slds-cell-wrap" style="vertical-align:top;">Canada</td></tr></tbody></table>

```
sf cmdt generate records --csv ~/Downloads/CMT_CSV_country.csv --type-name CmdtCountry
```

## Migrating Custom Settings and Custom Objects to Custom Metadata Types

When converting sObjects to a custom metadata type, unsupported object types are converted to a string format.

Mapping  
| sObject Type | Conversion Type |
| --- | --- |
| Auto-Number | Text field |
| Formula | Converted based on formula return type. If it is of text type converting it into a long text area with default length of 32768 |
| Lookup | Text field |
| Roll-Up summary | Text field |
| External lookup | Text field |
| Master detail | Text field |
| Encrypted text | Unreadable text string. |
| Geolocation | Two separate text fields representing the latitude and longitude |
| Multi-select picklist | Text field |
| Time | Text field |
| Currency | Text field |

#### See Also

- [Salesforce CLI Setup Guide](https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_intro.htm)