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>‑‑api‑version</code> | N/A | Type: Value<br><br>Override the api version used for api requests made by this command |
| <code>‑‑dev‑name</code> | <code>‑n</code> | Type: Value<br>Required<br><br>Name of the custom metadata type. |
| <code>‑‑flags‑dir</code> | N/A | Type: Value<br><br>Import flag values from a directory. |
| <code>‑‑ignore‑unsupported</code> | <code>‑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>‑‑json</code> | N/A | Type: Boolean<br><br>Format output as json. |
| <code>‑‑label</code> | <code>‑l</code> | Type: Value<br><br>Label for the custom metadata type. |
| <code>‑‑plural‑label</code> | <code>‑p</code> | Type: Value<br><br>Plural version of the label value; if blank, uses label. |
| <code>‑‑records‑output‑dir</code> | <code>‑r</code> | Type: Value<br>Default value: force-app/main/default/customMetadata<br><br>Directory to store newly-created custom metadata record files. |
| <code>‑‑sobject</code> | <code>‑s</code> | Type: Value<br>Required<br><br>API name of the source Salesforce object used to generate the custom metadata type. |
| <code>‑‑target‑org</code> | <code>‑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>‑‑type‑output‑directory</code> | <code>‑d</code> | Type: Value<br>Default value: force-app/main/default/objects<br><br>Directory to store newly-created custom metadata type files. |
| <code>‑‑visibility</code> | <code>‑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:
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:
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:
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:
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:
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:
sf cmdt generate fromorg --dev-name MyCMDT --sobject MySourceObject__c --records-output-dir path/to/my/cmdt/record/directory
<!-- prettier-ignore-end -->