cmdt Commands

Create and update custom metadata types and their records.

force:cmdt:create

Creates a new custom metadata type in the current project.

Examples for force:cmdt:create

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

1$ sfdx force:cmdt:create --typename MyCustomType

Create a protected custom metadata type with a specific label:

1$ sfdx force:cmdt:create --typename MyCustomType --label "Custom Type" --plurallabel "Custom Types" --visibility Protected

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/.sfdx/sfdx.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.

Examples for force:cmdt:field:create

Create a metadata file for a custom checkbox field:

1$ sfdx force:cmdt:field:create --fieldname MyField --fieldtype Checkbox

Create a metadata file for a custom picklist field:

1$ sfdx force:cmdt:field:create --fieldname MyField --fieldtype Picklist --picklistvalues "A,B,C"

Create a metadata file for a custom number field:

1$ sfdx force:cmdt:field:create --fieldname MyField --fieldtype Number --decimalplaces 2

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/.sfdx/sfdx.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.

Examples for force:cmdt:generate

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

1$ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c

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

1$ sfdx force:cmdt:generate --devname MyCMDT --sobjectname MySourceObject__c  --ignoreunsupported --targetusername 'alias or user email of the org containing the source type'

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

1$ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomObject__c  --visibility Protected

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

1$ sfdx force:cmdt:generate --devname MyCMDT --label "My CMDT" --plurallabel "My CMDTs" --sobjectname SourceCustomSetting__c  --visibility Protected

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

1$ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --typeoutputdir 'path/to/my/cmdt/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:

1$ sfdx force:cmdt:generate --devname MyCMDT --sobjectname SourceCustomSetting__c --recordsoutputdir 'path/to/my/cmdt/record/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/.sfdx/sfdx.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.

Examples for force:cmdt:record:create

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

1$ sfdx force:cmdt:record:create --typename MyCMT__mdt --recordname MyRecord My_Custom_Field_1=Foo My_Custom_Field_2=Bar

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

1$ sfdx force:cmdt:record:create --typename MyCMT__mdt --recordname MyRecord --label "My Record" --protected true My_Custom_Field_1=Foo My_Custom_Field_2=Bar

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/.sfdx/sfdx.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.

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:

1$ sfdx force:cmdt:record:insert --filepath path/to/my.csv --typename My_CMDT_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:

1$ sfdx force:cmdt:record:insert --filepath path/to/my.csv --typename My_CMDT_Name --inputdir "path/to/my/cmdt/directory" --namecolumn "PrimaryKey"

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/.sfdx/sfdx.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