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.

data:bulk:delete

Deletes a batch of records listed in a CSV file.

Command Syntax

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

Parameters

-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: file
-w | --wait WAIT
Optional




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

Type: minutes
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for 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:

1$ sfdx force:data:bulk:delete -s Account -f ./path/to/file.csv
1$ sfdx force:data:bulk:delete -s MyObject__c -f ./path/to/file.csv

data:bulk:status

Polls the Bulk API for job status or batch status.

Command Syntax

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

Parameters

-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
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for data:bulk:status

Examples:

1$ sfdx force:data:bulk:status -i 750xx000000005sAAA
1$ sfdx force:data:bulk:status -i 750xx000000005sAAA -b 751xx000000005nAAA

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
-s SOBJECTTYPE
-f CSVFILE
[-i EXTERNALID]
[-w WAIT]
[-u TARGETUSERNAME]
[--json]
[--loglevel LOGLEVEL]

Parameters

-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: file
-i | --externalid EXTERNALID
Optional




The column name of the external ID. If not provided, an arbitrary ID is used.

Type: id
-w | --wait WAIT
Optional




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

Type: minutes
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for 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:

1$ sfdx force:data:bulk:upsert -s MyObject__c -f ./path/to/file.csv -i MyField__c
1$ sfdx force:data:bulk:upsert -s MyObject__c -f ./path/to/file.csv -i Id -w 2

data:record:create

Creates and inserts a record.

Command Syntax

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

Parameters

-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
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for 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.

Enclose values that contain spaces in single quotes.

Examples:

1$ sfdx force:data:record:create -s Account -v "Name=Acme"
1$ sfdx force:data:record:create -s Account -v "Name='Universal Containers'"
1$ sfdx force:data:record:create -s Account -v "Name='Universal Containers' Website=www.example.com"

data:record:delete

Deletes a single record.

Command Syntax

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

Parameters

-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
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for 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.

Enclose values that contain spaces in single quotes.

Examples:

1$ sfdx force:data:record:delete -s Account -i 001D000000Kv3dl
1$ sfdx force:data:record:delete -s Account -w "Name=Acme"
1$ sfdx force:data:record:delete -s Account -w "Name='Universal Containers'"
1$ sfdx force:data:record:delete -s Account -w "Name='Universal Containers' Phone='(123) 456-7890'"

data:record:get

Displays a single record.

Command Syntax

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

Parameters

-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
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for 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.

Enclose values that contain spaces in single quotes.

Examples:

1$ sfdx force:data:record:get -s Account -i 001D000000Kv3dl
1$ sfdx force:data:record:get -s Account -w "Name=Acme"
1$ sfdx force:data:record:get -s Account -w "Name='Universal Containers'"
1$ sfdx force:data:record:get -s Account -w "Name='Universal Containers' Phone='(123) 456-7890'"

data:record:update

Updates a single record.

Command Syntax

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

Parameters

-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
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for 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.

Enclose values that contain spaces in single quotes.

Examples:

1$ sfdx force:data:record:update -s Account -i 001D000000Kv3dl -v "Name=NewAcme"
1$ sfdx force:data:record:update -s Account -w "Name='Old Acme'" -v "Name='New Acme'"
1$ sfdx force:data:record:update -s Account -i 001D000000Kv3dl -v "Name='Acme III' Website=www.example.com"

data:soql:query

Executes a SOQL query.

Command Syntax

sfdx force:data:soql:query
-q QUERY
[-t]
[-u TARGETUSERNAME]
[--json]
[--loglevel LOGLEVEL]

Parameters

-q | --query QUERY
Required




SOQL query to execute.

Type: string
-t | --usetoolingapi
Optional




Execute the query using Tooling API.

Type: flag
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for data:soql:query

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

Examples:

1$ sfdx force:data:soql:query -q "SELECT Id, Name, Account.Name FROM Contact"
1$ sfdx force:data:soql:query -q "SELECT Id, Name FROM Account WHERE ShippingState IN ('CA', 'NY')"
1$ sfdx force:data:soql:query -q "SELECT Name FROM ApexTrigger" -t

data:tree:export

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

Command Syntax

sfdx force:data:tree:export
-q QUERY
[-p]
[-x PREFIX]
[-d OUTPUTDIR]
[-u TARGETUSERNAME]
[--json]
[--loglevel LOGLEVEL]

Parameters

-q | --query QUERY
Required




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

Type: string
-p | --plan
Optional




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

Type: flag
-x | --prefix PREFIX
Optional




Prefix of generated files.

Type: string
-d | --outputdir OUTPUTDIR
Optional




Directory to store generated files.

Type: directory
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for data:tree:export

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

Examples:

1$ sfdx force:data:tree:export -q "SELECT Id, Name, (SELECT Name, Address__c FROM Properties__r) FROM Broker__c"
1$ sfdx force:data:tree:export -q <path to file containing soql query> -x export-demo -d /tmp/sfdx-out -p

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
[-f SOBJECTTREEFILES]
[-p PLAN]
[-c CONTENTTYPE]
[--confighelp]
[-u TARGETUSERNAME]
[--json]
[--loglevel LOGLEVEL]

Parameters

-f | --sobjecttreefiles SOBJECTTREEFILES
Optional




Ordered paths of JSON files containing a collection of record trees to insert. Either --sobjecttreefiles or --plan is required.

Type: filepath
-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
-c | --contenttype CONTENTTYPE
Optional




If the data file extension is not .json, provide the content type (applies to all files).

Type: string
--confighelp
Optional




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

Type: flag
-u | --targetusername TARGETUSERNAME
Optional




Username for the target org. Overrides the default target org.

Type: string
--json
Optional




Format output as JSON.

Type: flag
--loglevel LOGLEVEL
Optional




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

Type: string
Permissible values are: trace, debug, info, warn, error, fatal
Default value: error

Help for data:tree:import

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

Examples:

1$ sfdx force:data:tree:import -p data/accounts-contacts-plan.json -u me@my.org
1$ sfdx force:data:tree:import -f data/accounts-only.json data/contacts-only-1.json
1$ sfdx force:data:tree:import -p ./test/data/accounts-contacts-plan.json