1

Below are the available data related commands in CLI. If I want to insert records using SFDX CLI, how to do that?

force:data:bulk:delete    -- bulk delete records from a csv file
force:data:bulk:status    -- view the status of a bulk data load job or batch
force:data:bulk:upsert    -- bulk upsert records from a CSV file
force:data:record:create  -- create a record
force:data:record:delete  -- delete a record
force:data:record:get     -- view a record
force:data:record:update  -- update a record
force:data:soql:query     -- execute a SOQL query
force:data:tree:export    -- export data from an org into sObject tree format for force:data:tree:import consumption
force:data:tree:import    -- import data into an org using SObject Tree Save API

How can I use force:data:bulk:upsert command to insert records for a object which doesn't have External Id defined?

NOTE: I agree there are several options possible but I am more interested in using SFDX CLI to insert records.

2

You can use Id as the field to upsert against. There's even an example in the docs:

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

For new records, leave the Id column empty. Here's an example file I used that worked in my developer org (YMMV):

Id,Name
,Acme

This created a new account called Acme. Make sure you modify the -w parameter to give yourself enough polling time (this example is just 2 minutes), or you'll have to use force:data:bulk:status to check for completion and/or view the Bulk Job Monitoring screen in Setup.

2
  • I thought it was an example for updating records. Never thought I could leave Id column empty. This is great. – javanoob Sep 28 '19 at 17:57
  • @javanoob Glad to help, as always. – sfdcfox Sep 28 '19 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.