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