---
schema_version: "1"
id: af34cdd42adcfc041486e4cb7ccd1951f7e2253557c570d0d03c2bb215541b63
title: cmdt generate field
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforcedx/sfclireference/guides/cmdt/cli_reference_cmdt_generate_field.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-cli-reference/guide/cli_reference_cmdt_generate_field.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 2d4abacdcc7b824c831f092aad9c925c26c4da83c852d99583399aee0d90d612
products:
  - Salesforce CLI Command Reference
  - salesforcedx
---
<!-- prettier-ignore-start -->

# 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 |
|------------------|-------------------|-------------|
| <code>&#8209;&#8209;decimal&#8209;places</code> | <code>&#8209;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>&#8209;&#8209;flags&#8209;dir</code> | N/A | **Type:** Value<br><br>Import flag values from a directory. |
| <code>&#8209;&#8209;json</code> | N/A | **Type:** Boolean<br><br>Format output as json. |
| <code>&#8209;&#8209;label</code> | <code>&#8209;l</code> | **Type:** Value<br><br>Label for the field. |
| <code>&#8209;&#8209;name</code> | <code>&#8209;n</code> | **Type:** Value<br>**Required**<br><br>Unique name for the field. |
| <code>&#8209;&#8209;output&#8209;directory</code> | <code>&#8209;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>&#8209;&#8209;picklist&#8209;values</code> | <code>&#8209;p</code> | **Type:** Value<br><br>Picklist values; required for picklist fields. |
| <code>&#8209;&#8209;type</code> | <code>&#8209;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:

```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
```
<!-- prettier-ignore-end -->
