cmdt generate field

<!-- prettier-ignore-start -->

Generate a field for a custom metadata type based on the provided field type.

Description for cmdt generate field

Similar to a custom object, a custom metadata type has a list of custom fields that represent aspects of the metadata.

This command creates a metadata file that describes the new custom metadata type field. By default, the file is created in a "fields" directory in the current directory. Use the --output-directory to generate the file in the directory that contains the custom metadata type metdata files, such as "force-app/main/default/objects/MyCmdt__mdt" for the custom metadata type called MyCmdt.

Aliases for cmdt generate field

force:cmdt:field:create

cmdt:field:create

Flags

Flag Name (Long) Flag Name (Short) Description
<code>‑‑decimal‑places</code> <code>‑s</code> Type: Value<br><br>Number of decimal places to use for number or percent fields.<br><br>The value must be greater than or equal to zero. Default value is 0.
<code>‑‑flags‑dir</code> N/A Type: Value<br><br>Import flag values from a directory.
<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 field.
<code>‑‑name</code> <code>‑n</code> Type: Value<br>Required<br><br>Unique name for the field.
<code>‑‑output‑directory</code> <code>‑d</code> Type: Value<br><br>Directory to store newly-created field definition files.<br><br>New files are automatically created in the "fields" directory. The location can be an absolute path or relative to the current working directory. The default is the current directory.
<code>‑‑picklist‑values</code> <code>‑p</code> Type: Value<br><br>Picklist values; required for picklist fields.
<code>‑‑type</code> <code>‑f</code> Type: Value<br>Required<br>Valid Values: Checkbox, Date, DateTime, Email, Number, Percent, Phone, Picklist, Text, TextArea, LongTextArea, Url<br><br>Type of the field.<br><br>You can't use this command to create a custom metadata type field of type "Metadata Relationship". Use the Salesforce Setup UI instead.

Examples for cmdt generate field

Generate a metadata file for a custom checkbox field and add the file to the MyCmdt__mdt/fields directory:

sf cmdt generate field --name MyCheckboxField --type Checkbox --output-directory force-app/main/default/objects/MyCmdt__mdt

Generate a metadata file for a custom picklist field and add a few values:

sf cmdt generate field --name MyPicklistField --type Picklist --picklist-values A --picklist-values B --picklist-values C --output-directory force-app/main/default/objects/MyCmdt__mdt

Generate a metadata file for a custom number field and specify 2 decimal places:

sf cmdt generate field --name MyNumberField --type Number --decimal-places 2 --output-directory force-app/main/default/objects/MyCmdt__mdt
<!-- prettier-ignore-end -->