Skip to content

Execute SF CLI and DuckDB CLI commands within a Bash script to perform a Bulk Upsert operation on a Salesforce custom object

Notifications You must be signed in to change notification settings

datamike/sf-cli-bulkduck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Salesforce CLI BulkDuck

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.

Deploying the SFDX project locally

Note: This project was built using VS Code and the VS Code extensions for Salesforce CLI.

Prerequisites:

  1. Installed Salesforce CLI (Linux, Mac, or Windows Subsystem for Linux [WSL2])
  2. SF CLI authorization to a SF Developer org or other SF org
  3. Bash shell environment
  4. Installed DuckDB CLI
  5. jq Command Line JSON parser

Git Project

  1. After installing the prerequisites, clone the Github project.

  2. 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.'

Deploying the project to a Salesforce Developer org

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

Assign the Permission Set

'sf org assign permset --name Account_Measurement --target-org <<SF CLI alias name of the target SF org>>'

Load the Sample Account data

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>>'

Run the Bash script: scripts/bash/duckdb_sf_bulk_cli_ops.sh

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)

References

About

Execute SF CLI and DuckDB CLI commands within a Bash script to perform a Bulk Upsert operation on a Salesforce custom object

Topics

Resources

Stars

Watchers

Forks

Languages