---
schema_version: "1"
id: 311d1c6f4ddfd147391c38d35b4835f3195ec3069af1f0bcb3b946d93333f9e3
title: cmdt generate fromorg
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfclireference/guides/cmdt/cli_reference_cmdt_generate_fromorg.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-reference/guide/cli_reference_cmdt_generate_fromorg.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 67a6ade765919b4413c7c907ea6fde2af7de657cc5722e92c019852df17e4a26
products:
  - Salesforce CLI Command Reference
  - salesforcedx
---
<!-- prettier-ignore-start -->

# cmdt generate fromorg

Generate a custom metadata type and all its records from a Salesforce object.

## Description for cmdt generate fromorg

Use this command to migrate existing custom objects or custom settings in an org to custom metadata types. If a field of the Salesforce object is of an unsupported type, the field type is automatically converted to text. Run "sf cmdt generate field --help" to see the list of supported cmdt field types, listed in the --type flag summary. Use the --ignore-unsupported to ignore these fields.

This command creates the metadata files that describe the new custom metadata type and its fields in the "force-app/main/default/objects/TypeName__mdt" directory by default, where "TypeName" is the value of the required --dev-name flag. Use --type-output-directory to create them in a different directory.

## Aliases for cmdt generate fromorg

`force:cmdt:generate`

## Flags

| Flag Name (Long) | Flag Name (Short) | Description |
|------------------|-------------------|-------------|
| <code>&#8209;&#8209;api&#8209;version</code> | N/A | **Type:** Value<br><br>Override the api version used for api requests made by this command |
| <code>&#8209;&#8209;dev&#8209;name</code> | <code>&#8209;n</code> | **Type:** Value<br>**Required**<br><br>Name of the custom metadata type. |
| <code>&#8209;&#8209;flags&#8209;dir</code> | N/A | **Type:** Value<br><br>Import flag values from a directory. |
| <code>&#8209;&#8209;ignore&#8209;unsupported</code> | <code>&#8209;i</code> | **Type:** Boolean<br><br>Ignore unsupported field types.<br><br>In this context, "ignore" means that the fields aren't created. The default behavior is to create fields of type text and convert the field values to text. |
| <code>&#8209;&#8209;json</code> | N/A | **Type:** Boolean<br><br>Format output as json. |
| <code>&#8209;&#8209;label</code> | <code>&#8209;l</code> | **Type:** Value<br><br>Label for the custom metadata type. |
| <code>&#8209;&#8209;plural&#8209;label</code> | <code>&#8209;p</code> | **Type:** Value<br><br>Plural version of the label value; if blank, uses label. |
| <code>&#8209;&#8209;records&#8209;output&#8209;dir</code> | <code>&#8209;r</code> | **Type:** Value<br>**Default value:** `force-app/main/default/customMetadata`<br><br>Directory to store newly-created custom metadata record files. |
| <code>&#8209;&#8209;sobject</code> | <code>&#8209;s</code> | **Type:** Value<br>**Required**<br><br>API name of the source Salesforce object used to generate the custom metadata type. |
| <code>&#8209;&#8209;target&#8209;org</code> | <code>&#8209;o</code> | **Type:** Value<br>**Required**<br><br>Username or alias of the target org. Not required if the `target-org` configuration variable is already set. |
| <code>&#8209;&#8209;type&#8209;output&#8209;directory</code> | <code>&#8209;d</code> | **Type:** Value<br>**Default value:** `force-app/main/default/objects`<br><br>Directory to store newly-created custom metadata type files. |
| <code>&#8209;&#8209;visibility</code> | <code>&#8209;v</code> | **Type:** Value<br>**Valid Values:** `PackageProtected`, `Protected`, `Public`<br>**Default value:** `Public`<br><br>Who can see the custom metadata type.<br><br>For more information on what each option means, see this topic in Salesforce Help: https://help.salesforce.com/s/articleView?id=sf.custommetadatatypes_ui_create.htm&type=5. |

## Examples for cmdt generate fromorg

Generate a custom metadata type from a custom object called MySourceObject__c in your default org:

```shell
sf cmdt generate fromorg --dev-name MyCMDT --sobject MySourceObject__c
```

Generate a custom metadata type from a custom object in an org with alias my-scratch-org; ignore unsupported field types instead of converting them to text:

```shell
sf cmdt generate fromorg --dev-name MyCMDT --sobject MySourceObject__c --ignore-unsupported --target-org my-scratch-org
```

Generate a protected custom metadata type from a custom object:

```shell
sf cmdt generate fromorg --dev-name MyCMDT --sobject MySourceObject__c --visibility Protected
```

Generate a protected custom metadata type from a custom setting with a specific singular and plural label:

```shell
sf cmdt generate fromorg --dev-name MyCMDT --label "My CMDT" --plural-label "My CMDTs" --sobject MySourceSetting__c --visibility Protected
```

Generate a custom metadata type and put the resulting metadata files in the specified directory:

```shell
sf cmdt generate fromorg --dev-name MyCMDT --sobject MySourceObject__c --type-output-directory path/to/my/cmdt/directory
```

Generate a custom metadata type and put the resulting record metadata file(s) in the specified directory:

```shell
sf cmdt generate fromorg --dev-name MyCMDT --sobject MySourceObject__c --records-output-dir path/to/my/cmdt/record/directory
```
<!-- prettier-ignore-end -->
