# 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                                                                                                                                                                                                                                                                                                                                      |
| ------------------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `--api-version`           | N/A               | **Type:** Value<br><br>Override the api version used for api requests made by this command                                                                                                                                                                                                                                                       |
| `--dev-name`              | `-n`              | **Type:** Value<br>**Required**<br><br>Name of the custom metadata type.                                                                                                                                                                                                                                                                         |
| `--flags-dir`             | N/A               | **Type:** Value<br><br>Import flag values from a directory.                                                                                                                                                                                                                                                                                      |
| `--ignore-unsupported`    | `-i`              | **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.                                                                                                                      |
| `--json`                  | N/A               | **Type:** Boolean<br><br>Format output as json.                                                                                                                                                                                                                                                                                                  |
| `--label`                 | `-l`              | **Type:** Value<br><br>Label for the custom metadata type.                                                                                                                                                                                                                                                                                       |
| `--plural-label`          | `-p`              | **Type:** Value<br><br>Plural version of the label value; if blank, uses label.                                                                                                                                                                                                                                                                  |
| `--records-output-dir`    | `-r`              | **Type:** Value<br>**Default value:** `force-app/main/default/customMetadata`<br><br>Directory to store newly-created custom metadata record files.                                                                                                                                                                                              |
| `--sobject`               | `-s`              | **Type:** Value<br>**Required**<br><br>API name of the source Salesforce object used to generate the custom metadata type.                                                                                                                                                                                                                       |
| `--target-org`            | `-o`              | **Type:** Value<br>**Required**<br><br>Username or alias of the target org. Not required if the `target-org` configuration variable is already set.                                                                                                                                                                                              |
| `--type-output-directory` | `-d`              | **Type:** Value<br>**Default value:** `force-app/main/default/objects`<br><br>Directory to store newly-created custom metadata type files.                                                                                                                                                                                                       |
| `--visibility`            | `-v`              | **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
```
