A small Salesforce DX example project with Salesforce CLI and DuckDB CLI.
The CSV files and scripts provided will load 81 Account records into a SF org, then execute SF CLI and DuckDB CLI commands within a Bash shell script to perform a Bulk Upsert to the custom object Account_Measurement__c. The Account_Measurement_c object contains a Lookup relationship to the Account object.
Note: This project was built using VS Code and the VS Code extensions for Salesforce CLI.
- Installed Salesforce CLI (Linux, Mac, or Windows Subsystem for Linux [WSL2])
- SF CLI authorization to a SF Developer org or other SF org
- Bash shell environment
- Installed DuckDB CLI
- jq Command Line JSON parser
-
After installing the prerequisites, clone the Github project.
-
Verify that your Salesforce CLI, DuckDB CLI, and jq are installed and working.
Run the below commands from the terminal:
a. 'sf --version' b. 'duckdb -v' c. 'jq --version'
As far as Salesforce metadata, the example Salesforce custom object is: 'Account_Measurement__c.'
To deploy the Sample custom object and associated metadata to a developer org (or scratch org), run the following command from the project's root folder 'sf-cli-bulkduck':
'sf project deploy start --source-dir force-app --target-org <<SF CLI alias name of the target SF org>>'
This will deploy 2 Page Layouts, 2 Objects (Account - with some custom fields - and Account_Measurement__c), 1 Permission Set, and 1 Custom Tab
'sf org assign permset --name Account_Measurement --target-org <<SF CLI alias name of the target SF org>>'
To load the the Sample Account data to a developer org, run the following command:
'sf data import bulk --file data/Account_data.csv --sobject Account --wait 3 --targt-org <<SF CLI alias name of the target SF org>>'
From the bash terminal (in directory 'sf-cli-bulkduck'), run the following command:
'bash scripts/bash/duckdb_sf_bulk_cli_ops.sh'
NOTE: External Id for the Bulk Upsert needs to be Account_Customer_ID__c (this gets placed in the DuckDB CLI-transformed CSV file)
- Salesforce CLI Setup Guide
- Salesforce CLI Command Reference
- DuckDB Setup Guide
- DuckDB CLI Reference
- I received inspiration and ideas from this blog post about using the Salesforce CLI for data operations Salesforce Developer Blog by Phillipe Ozil from Feb. 2024