cmdt generate fromorg

Generate a custom metadata type and all its records from a Salesforce object.

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.

force:cmdt:generate

Flag Name (Long)Flag Name (Short)Description
‑‑api‑versionN/AType: Value

Override the api version used for api requests made by this command
‑‑dev‑name‑nType: Value
Required

Name of the custom metadata type.
‑‑flags‑dirN/AType: Value

Import flag values from a directory.
‑‑ignore‑unsupported‑iType: Boolean

Ignore unsupported field types.

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.
‑‑jsonN/AType: Boolean

Format output as json.
‑‑label‑lType: Value

Label for the custom metadata type.
‑‑plural‑label‑pType: Value

Plural version of the label value; if blank, uses label.
‑‑records‑output‑dir‑rType: Value
Default value: force-app/main/default/customMetadata

Directory to store newly-created custom metadata record files.
‑‑sobject‑sType: Value
Required

API name of the source Salesforce object used to generate the custom metadata type.
‑‑target‑org‑oType: Value
Required

Username or alias of the target org. Not required if the target-org configuration variable is already set.
‑‑type‑output‑directory‑dType: Value
Default value: force-app/main/default/objects

Directory to store newly-created custom metadata type files.
‑‑visibility‑vType: Value
Valid Values: PackageProtected, Protected, Public
Default value: Public

Who can see the custom metadata type.

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.

Generate a custom metadata type from a custom object called MySourceObject__c in your default org:

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:

Generate a protected custom metadata type from a custom object:

Generate a protected custom metadata type from a custom setting with a specific singular and plural label:

Generate a custom metadata type and put the resulting metadata files in the specified directory:

Generate a custom metadata type and put the resulting record metadata file(s) in the specified directory: