cmdt Commands

Create and update custom metadata types and their records.

force:cmdt:create

Creates a new custom metadata type in the current project.

As of April 20, 2023, we no longer maintain this section of the command reference. Refer to the reference information about the sf-style commands instead, which we update regularly. We keep this reference information about the sfdx-style commands as-is for historical reference only.

Don't worry, this command and its flags continue to work the same as before, and any scripts that use the command won’t break. However, we recommend that you start using the equivalent sf-style cmdt generate object command instead. Here’s how the flags changed between the old and new commands; if a flag isn't listed, the old and new names are the same:

  • Removed flag: --loglevel. Use the SF_LOG_LEVEL environment variable instead.
  • Changed flag name: Old name --apiversion. New name: --api-version.
  • Changed flag name: Old name --outputdir. New name: --output-directory.
  • Changed flag name: Old name --plurallabel. New name: --plural-label.
  • Changed flag name: Old name --typename. New name: --type-name.

For background information about this change, read this blog post, which describes how we've updated many of the existing sfdx commands to use the improvements we made in sf. We improved this particular command on January 19, 2023.

Warning

Examples for force:cmdt:create

Create a custom metadata type with developer name 'MyCustomType'; this name will also be used as the label:

Create a protected custom metadata type with a specific label:

Command Syntax

sfdx force:cmdt:create
[--json]
[--loglevel LOGLEVEL]
-n TYPENAME
[-l LABEL]
[-p PLURALLABEL]
[-v VISIBILITY]
[-d OUTPUTDIR]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sf/sf.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --typename TYPENAME
Required

The unique name of the object in the API. This name can contain only underscores and alphanumeric characters, and must be unique in your org. It must begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.

Type: string
-l | --label LABEL
Optional

A label for the custom metadata type.

Type: string
-p | --plurallabel PLURALLABEL
Optional

The plural version of the label value. If this flag is missing or blank, the singular label is used as the plural label.

Type: string
-v | --visibility VISIBILITY
Optional

The visibility of the custom metadata type.

Type: enum
Permissible values are: PackageProtected, Protected, Public
Default value: Public
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly-created custom metadata type files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: directory

force:cmdt:field:create

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

As of April 20, 2023, we no longer maintain this section of the command reference. Refer to the reference information about the sf-style commands instead, which we update regularly. We keep this reference information about the sfdx-style commands as-is for historical reference only.

Don't worry, this command and its flags continue to work the same as before, and any scripts that use the command won’t break. However, we recommend that you start using the equivalent sf-style cmdt generate field command instead. Here’s how the flags changed between the old and new commands; if a flag isn't listed, the old and new names are the same:

  • Removed flag: --loglevel. Use the SF_LOG_LEVEL environment variable instead.
  • Changed flag name: Old name --apiversion. New name: --api-version.
  • Changed flag name: Old name --decimalplaces. New name: --decimal-places.
  • Changed flag name: Old name --fieldname. New name: --field-name.
  • Changed flag name: Old name --fieldtype. New name: --field-type.
  • Changed flag name: Old name --outputdir. New name: --output-directory.
  • Changed flag name: Old name --picklistvalues. New name: --picklist-values.

For background information about this change, read this blog post, which describes how we've updated many of the existing sfdx commands to use the improvements we made in sf. We improved this particular command on January 19, 2023.

Warning

Examples for force:cmdt:field:create

Create a metadata file for a custom checkbox field:

Create a metadata file for a custom picklist field:

Create a metadata file for a custom number field:

Command Syntax

sfdx force:cmdt:field:create
[--json]
[--loglevel LOGLEVEL]
-n FIELDNAME
-f FIELDTYPE
[-p PICKLISTVALUES]
[-s DECIMALPLACES]
[-l LABEL]
[-d OUTPUTDIR]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sf/sf.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-n | --fieldname FIELDNAME
Required

The unique name for the field.

Type: string
-f | --fieldtype FIELDTYPE
Required

The unique name for the field.

Type: enum
Permissible values are: Checkbox, Date, DateTime, Email, Number, Percent, Phone, Picklist, Text, TextArea, LongTextArea, Url
-p | --picklistvalues PICKLISTVALUES
Optional

A comma-separated list of picklist values. These values are required when creating a Picklist field.

Type: array
-s | --decimalplaces DECIMALPLACES
Optional

The number of decimal places to use for Number or Percent fields. The value must be greater than or equal to zero.

Type: number
-l | --label LABEL
Optional

The label for the field.

Type: string
-d | --outputdir OUTPUTDIR
Optional

The directory to store the newly-created field definition files. The location can be an absolute path or relative to the current working directory. The default is the current directory.

Type: directory

force:cmdt:generate

Generates a custom metadata type and all its records for the provided sObject.

As of April 20, 2023, we no longer maintain this section of the command reference. Refer to the reference information about the sf-style commands instead, which we update regularly. We keep this reference information about the sfdx-style commands as-is for historical reference only.

Don't worry, this command and its flags continue to work the same as before, and any scripts that use the command won’t break. However, we recommend that you start using the equivalent sf-style cmdt generate fromorg command instead. Here’s how the flags changed between the old and new commands; if a flag isn't listed, the old and new names are the same:

  • Removed flag: --loglevel. Use the SF_LOG_LEVEL environment variable instead.
  • Changed flag name: Old name --apiversion. New name: --api-version.
  • Changed flag name: Old name --devname. New name: --dev-name.
  • Changed flag name: Old name --ignoreunsupported. New name: --ignore-unsupported.
  • Changed flag name: Old name --plurallabel. New name: --plural-label.
  • Changed flag name: Old name --recordsoutputdir. New name: --records-output-dir.
  • Changed flag name: Old name --sobjectname. New name: --sobject.
  • Changed flag name: Old name --typeoutputdir. New name: --type-output-directory.

For background information about this change, read this blog post, which describes how we've updated many of the existing sfdx commands to use the improvements we made in sf. We improved this particular command on January 19, 2023.

Warning

Examples for force:cmdt:generate

Generate a custom metadata type from an sObject in the default target org:

Generate a custom metadata type from an sObject in the specified target org; ignore unsupported field types instead of converting them to text:

Generate a protected custom metadata type from an sObject in the default target org:

Generate a protected custom metadata type with a specific label from an sObject in the default target org:

Generate a custom metadata type from an sObject in the default target org; put the resulting type metadata file in the specified directory:

Generate a custom metadata type from an sObject in the default target org; put the resulting record metadata file(s) in the specified directory:

Command Syntax

sfdx force:cmdt:generate
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-n DEVNAME
[-l LABEL]
[-p PLURALLABEL]
[-v VISIBILITY]
-s SOBJECTNAME
[-i]
[-d TYPEOUTPUTDIR]
[-r RECORDSOUTPUTDIR]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sf/sf.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-u | --targetusername TARGETUSERNAME
Optional

A username or alias for the target org. Overrides the default target org.

Type: string
--apiversion APIVERSION
Optional

Override the API version used for API requests made by this command.

Type: string
-n | --devname DEVNAME
Required

The name of the custom metadata type.

Type: string
-l | --label LABEL
Optional

The label for the custom metadata type.

Type: string
-p | --plurallabel PLURALLABEL
Optional

The plural version of the label value. If this flag is missing or blank, the singular label is used as the plural label.

Type: string
-v | --visibility VISIBILITY
Optional

The visibility of the custom metadata type.

Type: enum
Permissible values are: PackageProtected, Protected, Public
Default value: Public
-s | --sobjectname SOBJECTNAME
Required

The API name of the sObject source for custom metadata generation.

Type: string
-i | --ignoreunsupported
Optional

Ignore unsupported field types (these fields will not be created). The default is to create Text fields and convert the source value to text.

Type: boolean
-d | --typeoutputdir TYPEOUTPUTDIR
Optional

The directory to store newly-created custom metadata type files.

Type: directory
Default value: force-app/main/default/objects
-r | --recordsoutputdir RECORDSOUTPUTDIR
Optional

The directory to store newly-created custom metadata record files.

Type: directory
Default value: force-app/main/default/customMetadata

force:cmdt:record:create

Create a new record for a given custom metadata type in the current project.

As of April 20, 2023, we no longer maintain this section of the command reference. Refer to the reference information about the sf-style commands instead, which we update regularly. We keep this reference information about the sfdx-style commands as-is for historical reference only.

Don't worry, this command and its flags continue to work the same as before, and any scripts that use the command won’t break. However, we recommend that you start using the equivalent sf-style cmdt generate record command instead. Here’s how the flags changed between the old and new commands; if a flag isn't listed, the old and new names are the same:

  • Removed flag: --loglevel. Use the SF_LOG_LEVEL environment variable instead.
  • Changed flag name: Old name --apiversion. New name: --api-version.
  • Changed flag name: Old name --inputdir. New name: --input-directory.
  • Changed flag name: Old name --outputdir. New name: --output-directory.
  • Changed flag name: Old name --recordname. New name: --record-name.
  • Changed flag name: Old name --typename. New name: --type-name.

For background information about this change, read this blog post, which describes how we've updated many of the existing sfdx commands to use the improvements we made in sf. We improved this particular command on January 19, 2023.

Warning

Examples for force:cmdt:record:create

Create a record metadata file for custom metadata type 'MyCMT' with values specified for two custom fields:

Create a protected record metadata file for custom metadata type 'MyCMT' with a specific label and values specified for two custom fields:

Command Syntax

sfdx force:cmdt:record:create
[--json]
[--loglevel LOGLEVEL]
-t TYPENAME
-n RECORDNAME
[-l LABEL]
[-p PROTECTED]
[-i INPUTDIR]
[-d OUTPUTDIR]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sf/sf.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-t | --typename TYPENAME
Required

The API name of the custom metadata type to create a record for.

Type: string
-n | --recordname RECORDNAME
Required

The name for the new record.

Type: string
-l | --label LABEL
Optional

The label for the new record.

Type: string
-p | --protected PROTECTED
Optional

Protect the record when it is in a managed package. Protected records can only be accessed by code in the same managed package namespace.

Type: string
Permissible values are: true, false
Default value: false
-i | --inputdir INPUTDIR
Optional

The directory to pull the custom metadata type definition from.

Type: directory
Default value: force-app/main/default/objects
-d | --outputdir OUTPUTDIR
Optional

The directory to store newly-created custom metadata record files.

Type: directory
Default value: force-app/main/default/customMetadata

force:cmdt:record:insert

Create new custom metadata type records from a CSV file.

As of April 20, 2023, we no longer maintain this section of the command reference. Refer to the reference information about the sf-style commands instead, which we update regularly. We keep this reference information about the sfdx-style commands as-is for historical reference only.

Don't worry, this command and its flags continue to work the same as before, and any scripts that use the command won’t break. However, we recommend that you start using the equivalent sf-style cmdt generate records command instead. Here’s how the flags changed between the old and new commands; if a flag isn't listed, the old and new names are the same:

  • Removed flag: --loglevel. Use the SF_LOG_LEVEL environment variable instead.
  • Changed flag name: Old name --apiversion. New name: --api-version.
  • Changed flag name: Old name --filepath. New name: --csv.
  • Changed flag name: Old name --inputdir. New name: --input-directory.
  • Changed flag name: Old name --namecolumn. New name: --name-column.
  • Changed flag name: Old name --outputdir. New name: --output-directory.
  • Changed flag name: Old name --typename. New name: --type-name.

For background information about this change, read this blog post, which describes how we've updated many of the existing sfdx commands to use the improvements we made in sf. We improved this particular command on January 19, 2023.

Warning

Examples for force:cmdt:record:insert

Create record metadata files for type 'My_CMDT_Name' (from your local project) based on values in a CSV file, using 'Name' as the column that specifies the record name:

Create record metadata files for type 'My_CMDT_Name' (from the specified directory) based on values in a CSV file, using 'PrimaryKey' as the column that specifies the record name:

Command Syntax

sfdx force:cmdt:record:insert
[--json]
[--loglevel LOGLEVEL]
-f FILEPATH
-t TYPENAME
[-i INPUTDIR]
[-d OUTPUTDIR]
[-n NAMECOLUMN]

Parameters

--json
Optional

Format output as JSON.

Type: boolean
--loglevel LOGLEVEL
Optional

The logging level for this command invocation. Logs are stored in $HOME/.sf/sf.log.

Type: enum
Permissible values are: trace, debug, info, warn, error, fatal, TRACE, DEBUG, INFO, WARN, ERROR, FATAL
Default value: warn
-f | --filepath FILEPATH
Required

The path to the CSV file.

Type: string
-t | --typename TYPENAME
Required

The API Name of the custom metadata type. The '__mdt' suffix will be appended to the end of the name if it is omitted.

Type: string
-i | --inputdir INPUTDIR
Optional

The directory to pull the custom metadata type definition from.

Type: directory
Default value: force-app/main/default/objects
-d | --outputdir OUTPUTDIR
Optional

The directory to store newly-created custom metadata record files.

Type: directory
Default value: force-app/main/default/customMetadata
-n | --namecolumn NAMECOLUMN
Optional

The column that is used to determine the name of the record.

Type: string
Default value: Name