I am currently learning Salesforce DX/CLI to pull in data from my org.
I use the following syntax to extract Accounts data.
sfdx force:data:soql:query -u vpy.lightninglearn@gmail.com --query "SELECT ID, NAME FROM Account"
Questions
a) Is it possible to source the query from a file instead of in the command (as many times the SOQL query may span across several lines) ?
b) Is it possible to store the output into a file instead of just displaying the results in the Command Prompt (as seen below) ?
Best Answer
Use batch script to get SOQL from file or write to file.
Fetch SOQL from File
Read SOQL from file into a variable and use the variable in the sfdx command. Here's a simple
bat
file example (there are limitations toset
).Print output
Pipe the output to print data to a file. For e.g. the below command will output CSV to the file.