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 with the SObject Tree Save API. Perform simple CRUD operations on individual records with the REST API.

force:data:bulk:delete

Bulk delete records from a csv file.

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 for force:data:bulk:delete

Command Syntax

sfdx force:data:bulk:delete
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
-f CSVFILE
-s SOBJECTTYPE
[-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/.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
-f | --csvfile CSVFILE
Required

The path to the CSV file containing the ids of the records to delete.

Type: filepath
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the records you’re deleting.

Type: string
-w | --wait WAIT
Optional

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

Type: minutes

force:data:bulk:status

View the status of a bulk data load job or batch.

Help for force:data:bulk:status

Run this command using the job ID or batch ID returned from the force:data:bulk:delete or force:data:bulk:upsert commands.

Examples for force:data:bulk:status

Command Syntax

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

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
-b | --batchid BATCHID
Optional

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

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: string

force:data:bulk:upsert

Bulk upsert records from a CSV file.

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.

By default, the job runs the batches in parallel. Specify --serial to run them serially.

Examples for force:data:bulk:upsert

Command Syntax

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

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
-i | --externalid EXTERNALID
Required

The column name of the external ID.

Type: string
-f | --csvfile CSVFILE
Required

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

Type: filepath
-s | --sobjecttype SOBJECTTYPE
Required

The sObject type of the records you want to upsert.

Type: string
-w | --wait WAIT
Optional

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

Type: minutes
-r | --serial
Optional

Run batches in serial mode.

Type: boolean

force:data:record:create

Creates and inserts a record.

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 for force:data:record:create

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

The 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 with tooling api.

Type: boolean
--perflog
Optional

Get API performance data.

Type: boolean

force:data:record:delete

Deletes a single record.

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 for force:data:record:delete

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

The 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 with Tooling API.

Type: boolean
--perflog
Optional

Get API performance data.

Type: boolean

force:data:record:get

Displays a single record.

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 for force:data:record:get

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

The 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 with Tooling API.

Type: boolean
--perflog
Optional

Get API performance data.

Type: boolean

force:data:record:update

Updates a single record.

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 for force:data:record:update

$sfdx force:data:record:update -s Account -i 001D000000Kv3dl -v "Name=NewAcme" --perflog --json

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/.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
-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 with Tooling API.

Type: boolean
--perflog
Optional

Get API performance data.

Type: boolean

force:data:soql:bulk:report

View the status of a bulk query.

Help for force:data:soql:bulk:report

Run this command using the job ID returned from the force:data:soql:query --bulk command.

Examples for force:data:soql:bulk:report

Command Syntax

sfdx force:data:soql:bulk:report
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
[-q QUERY]
[-f SOQLQUERYFILE]
[-t]
[-b]
[-w WAIT]
[-r RESULTFORMAT]
[--perflog]
-i BULKQUERYID

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
-q | --query QUERY
Optional

SOQL query to execute.

Type: string
-f | --soqlqueryfile SOQLQUERYFILE
Optional

A SOQL query stored in a file.

Type: filepath
-t | --usetoolingapi
Optional

Execute query with Tooling API.

Type: boolean
-b | --bulk
Optional

Use the bulk 2.0 API to query data.

Type: boolean
-w | --wait WAIT
Optional

Wait time for command to finish in minutes.

Type: minutes
-r | --resultformat RESULTFORMAT
Optional

Result format emitted to stdout; --json flag overrides this parameter.

Type: enum
Permissible values are: human, csv, json
Default value: human
--perflog
Optional

Get API performance data.

Type: boolean
-i | --bulkqueryid BULKQUERYID
Required

The job ID of the bulk query.

Type: string

force:data:soql:query

Execute a SOQL query.

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 for force:data:soql:query

Command Syntax

sfdx force:data:soql:query
[--json]
[--loglevel LOGLEVEL]
[-u TARGETUSERNAME]
[--apiversion APIVERSION]
[-q QUERY]
[-f SOQLQUERYFILE]
[-t]
[-b]
[-w WAIT]
[-r RESULTFORMAT]
[--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/.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
-q | --query QUERY
Optional

SOQL query to execute.

Type: string
-f | --soqlqueryfile SOQLQUERYFILE
Optional

A SOQL query stored in a file.

Type: filepath
-t | --usetoolingapi
Optional

Execute query with Tooling API.

Type: boolean
-b | --bulk
Optional

Use the bulk 2.0 API to query data.

Type: boolean
-w | --wait WAIT
Optional

Wait time for command to finish in minutes.

Type: minutes
-r | --resultformat RESULTFORMAT
Optional

Result format emitted to stdout; --json flag overrides this parameter.

Type: enum
Permissible values are: human, csv, json
Default value: human
--perflog
Optional

Get API performance data.

Type: boolean

force:data:tree:export

Export data from an org.

Help for force:data:tree:export

Exports data from an org into sObject tree format for use with the force:data:tree:import command.

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

Examples for force:data:tree:export

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/.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
-q | --query QUERY
Required

Soql query, or filepath of file containing a soql query, to retrieve records.

Type: string
-p | --plan
Optional

Generate mulitple 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 files'.

Type: directory

force:data:tree:import

Import data into an org.

Help for force:data:tree:import

IMPORTANT: Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.

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

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

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

Examples for force:data:tree:import

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

Comma-delimited, ordered paths of json files containing collection of record trees to insert.

Type: array
-p | --plan PLAN
Optional

Path to plan to insert multiple data files that have master-detail relationships.

Type: filepath
--confighelp
Optional

Display schema information for the --plan configuration file to stdout; if you use this option, all other options except --json are ignored.

Type: boolean