# cmdt generate field

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                                                                                                                                                                                                                                                                                                                                                |
| -------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `--decimal-places`   | `-s`              | **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.                                                                                                                                                                                           |
| `--flags-dir`        | N/A               | **Type:** Value<br><br>Import flag values from a directory.                                                                                                                                                                                                                                                                                                |
| `--json`             | N/A               | **Type:** Boolean<br><br>Format output as json.                                                                                                                                                                                                                                                                                                            |
| `--label`            | `-l`              | **Type:** Value<br><br>Label for the field.                                                                                                                                                                                                                                                                                                                |
| `--name`             | `-n`              | **Type:** Value<br>**Required**<br><br>Unique name for the field.                                                                                                                                                                                                                                                                                          |
| `--output-directory` | `-d`              | **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.                                                                             |
| `--picklist-values`  | `-p`              | **Type:** Value<br><br>Picklist values; required for picklist fields.                                                                                                                                                                                                                                                                                      |
| `--type`             | `-f`              | **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:

```shell
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:

```shell
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:

```shell
sf cmdt generate field --name MyNumberField --type Number --decimal-places 2 --output-directory force-app/main/default/objects/MyCmdt__mdt
```
