data Commands

Use the data commands to manipulate records in your org. Commands are available to help you work with various APIs. Import CSV files with the Bulk API. Export and import data that includes master-detail relationships with the SObject Tree Save API. Perform simple CRUD operations on individual records with the REST API.

force:data:bulk:delete

Deletes a batch of records listed in a CSV file.

Command Syntax

sfdx force:data:bulk:delete
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-s SOBJECTTYPE
-f CSVFILE
[-w WAIT]

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
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the records you’re deleting.

Type: string
-f | --csvfile CSVFILE
Required

The path to the CSV file that contains the IDs of the records to delete.

Type: filepath
-w | --wait WAIT
Optional

The number of minutes to wait for the command to complete before displaying the results.

Type: minutes

Help for force:data:bulk:delete

The file must be a CSV file with only one column: "Id".

One job can contain many batches, depending on the length of the CSV file.

Returns a job ID and a batch ID. Use these IDs to check job status with data:bulk:status.

Examples:

force:data:bulk:status

Polls the Bulk API for job status or batch status.

Command Syntax

sfdx force:data:bulk:status
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-i JOBID
[-b BATCHID]

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
-i | --jobid JOBID
Required

The ID of the job you want to view or of the job whose batch you want to view.

Type: id
-b | --batchid BATCHID
Optional

The ID of the batch whose status you want to view.

Type: id

Help for force:data:bulk:status

Examples:

force:data:bulk:upsert

Creates a job and one or more batches for inserting new rows and updating existing rows by accessing the Bulk API.

Command Syntax

sfdx force:data:bulk:upsert
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-s SOBJECTTYPE
-f CSVFILE
-i EXTERNALID
[-w WAIT]

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
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the records you want to upsert.

Type: string
-f | --csvfile CSVFILE
Required

The path to the CSV file that defines the records to upsert.

Type: filepath
-i | --externalid EXTERNALID
Required

The column name of the external ID.

Type: string
-w | --wait WAIT
Optional

The number of minutes to wait for the command to complete before displaying the results.

Type: minutes

Help for force:data:bulk:upsert

Inserts or updates records from a CSV file.

One job can contain many batches, depending on the length of the CSV file.

Returns a job ID and a batch ID. Use these IDs to check job status with data:bulk:status.

For information about formatting your CSV file, see "Prepare CSV Files" in the Bulk API Developer Guide.

Examples:

force:data:record:create

Creates and inserts a record.

Command Syntax

sfdx force:data:record:create
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-s SOBJECTTYPE
-v VALUES
[-t]
[--perflog]

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
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the record you’re creating.

Type: string
-v | --values VALUES
Required

The <fieldName>=<value> pairs you’re creating.

Type: string
-t | --usetoolingapi
Optional

Create the record using Tooling API.

Type: boolean
--perflog
Optional

Gets data on API performance metrics from the server. The data is stored in $HOME/.sfdx/apiPerformanceLog.json

Type: boolean

Help for force:data:record:create

The format of a field-value pair is <fieldName>=<value>.

Enclose all field-value pairs in one set of double quotation marks, delimited by spaces.

Enclose values that contain spaces in single quotes.

To get data on API performance metrics, specify both --perflog and --json.

Examples:

force:data:record:delete

Deletes a single record.

Command Syntax

sfdx force:data:record:delete
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-s SOBJECTTYPE
[-i SOBJECTID]
[-w WHERE]
[-t]
[--perflog]

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
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the record you’re deleting.

Type: string
-i | --sobjectid SOBJECTID
Optional

The ID of the record you’re deleting.

Type: id
-w | --where WHERE
Optional

A list of <fieldName>=<value> pairs to search for.

Type: string
-t | --usetoolingapi
Optional

Delete the record using Tooling API.

Type: boolean
--perflog
Optional

Gets data on API performance metrics from the server. The data is stored in $HOME/.sfdx/apiPerformanceLog.json

Type: boolean

Help for force:data:record:delete

Specify an sObject type and either an ID or a list of <fieldName>=<value> pairs.

The format of a field-value pair is <fieldName>=<value>.

Enclose all field-value pairs in one set of double quotation marks, delimited by spaces.

Enclose values that contain spaces in single quotes.

To get data on API performance metrics, specify both --perflog and --json.

Examples:

force:data:record:get

Displays a single record.

Command Syntax

sfdx force:data:record:get
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-s SOBJECTTYPE
[-i SOBJECTID]
[-w WHERE]
[-t]
[--perflog]

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
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the record you’re retrieving.

Type: string
-i | --sobjectid SOBJECTID
Optional

The ID of the record you’re retrieving.

Type: id
-w | --where WHERE
Optional

A list of <fieldName>=<value> pairs to search for.

Type: string
-t | --usetoolingapi
Optional

Retrieve the record using Tooling API.

Type: boolean
--perflog
Optional

Gets data on API performance metrics from the server. The data is stored in $HOME/.sfdx/apiPerformanceLog.json

Type: boolean

Help for force:data:record:get

Specify an sObject type and either an ID or a list of <fieldName>=<value> pairs.

The format of a field-value pair is <fieldName>=<value>.

Enclose all field-value pairs in one set of double quotation marks, delimited by spaces.

Enclose values that contain spaces in single quotes.

To get data on API performance metrics, specify both --perflog and --json.

Examples:

force:data:record:update

Updates a single record.

Command Syntax

sfdx force:data:record:update
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-s SOBJECTTYPE
[-i SOBJECTID]
[-w WHERE]
-v VALUES
[-t]
[--perflog]

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
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the record you’re updating.

Type: string
-i | --sobjectid SOBJECTID
Optional

The ID of the record you’re updating.

Type: id
-w | --where WHERE
Optional

A list of <fieldName>=<value> pairs to search for.

Type: string
-v | --values VALUES
Required

The <fieldName>=<value> pairs you’re updating.

Type: string
-t | --usetoolingapi
Optional

Update the record using Tooling API.

Type: boolean
--perflog
Optional

Gets data on API performance metrics from the server. The data is stored in $HOME/.sfdx/apiPerformanceLog.json

Type: boolean

Help for force:data:record:update

The format of a field-value pair is <fieldName>=<value>.

Enclose all field-value pairs in one set of double quotation marks, delimited by spaces.

Enclose values that contain spaces in single quotes.

To get data on API performance metrics, specify both --perflog and --json.

Examples:

force:data:soql:query

Executes a SOQL query.

Command Syntax

sfdx force:data:soql:query
[--json]
[--loglevel LOGLEVEL]
[-r RESULTFORMAT]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-q QUERY
[-t]
[--perflog]

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
-r | --resultformat RESULTFORMAT
Optional

Format to use when displaying results. If you also specify the --json flag, --json overrides this parameter.

Type: enum
Permissible values are: human, csv, json
Default value: human
-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
-q | --query QUERY
Required

SOQL query to execute.

Type: string
-t | --usetoolingapi
Optional

Execute the query using Tooling API.

Type: boolean
--perflog
Optional

Gets data on API performance metrics from the server. The data is stored in $HOME/.sfdx/apiPerformanceLog.json

Type: boolean

Help for force:data:soql:query

When you execute this command in a project, it executes the query against the data in your default scratch org.

To get data on API performance metrics, specify both --perflog and --json.

Examples:

force:data:tree:export

Exports data from an org into sObject tree format for force:data:tree:import consumption.

Command Syntax

sfdx force:data:tree:export
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-q QUERY
[-p]
[-x PREFIX]
[-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
-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
-q | --query QUERY
Required

A SOQL query statement or the path of a file containing a SOQL query statement to retrieve the records to export.

Type: string
-p | --plan
Optional

Generates multiple sObject tree files and a plan definition file for aggregated import.

Type: boolean
-x | --prefix PREFIX
Optional

Prefix of generated files.

Type: string
-d | --outputdir OUTPUTDIR
Optional

Directory to store generated files.

Type: directory

Help for force:data:tree:export

Generates JSON files for use with the force:data:tree:import command.

Examples:

For more information and examples, run "sfdx force:data:tree:import -h".

The query for export can return a maximum of 2,000 records. For more information, see the REST API Developer Guide: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobject_tree.htm

force:data:tree:import

Imports data into an org using the SObject Tree Save API. This data can include master-detail relationships.

Command Syntax

sfdx force:data:tree:import
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
[-f SOBJECTTREEFILES]
[-p PLAN]
[--confighelp]

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
-f | --sobjecttreefiles SOBJECTTREEFILES
Optional

Comma-delimited, ordered paths of JSON files containing a collection of record trees to insert. Either --sobjecttreefiles or --plan is required.

Type: array
-p | --plan PLAN
Optional

Path to plan to insert multiple data files that have master-detail relationships. Either --sobjecttreefiles or --plan is required.

Type: filepath
--confighelp
Optional

Displays the schema information for the configuration file. If you use this option, all other options, except --json, are ignored.

Type: boolean

Help for force:data:tree:import

To generate JSON files for use with force:data:tree:import, run "sfdx force:data:tree:export".

Examples:

To import records as individual files, first run the export commands:

Then run the import command:

To import multiple data files as part of a plan, first run the export command with the -p | --plan flag:

Then run the import command, supplying a filepath value for the -p | --plan parameter:

The SObject Tree API supports requests that contain up to 200 records. For more information, see the REST API Developer Guide: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobject_tree.htm