6

When using the sfdx force:data:tree:export command, the Salesforce Developer Documentation states you can specify a file path in place of an in-line typed query (either option would follow the -q flag). I ran a simple query using the in-line version first :

sfdx:force:data:tree:export -q "SELECT Id FROM Account LIMIT 5" -d queries/accounts/ -u DevHub

And it created the json and path files without issue.

However, when I tried to swap out the in-line query for a file path directed at accountsquery.file which contains the exact same query string, I keep getting the following error:

➜  testProject sfdx force:data:tree:export -q queries/accountsquery -d queries/accounts/ -u DevHub

ERROR:  Invalid SOQL query: "select id from account".

Does the file need to be of a certain extension type? Is the syntax somehow different when you specify a file path? I'm not sure what I'm doing wrong, and I can't find an example of using the file path over an in-line string anywhere.

2 Answers 2

6

I just tried executing by create a simple file in a folder as shown in the below screenshot and below command worked fine

sfdx force:data:tree:export -q data/accounts/queryFile -d data/accounts/

My folder structure is as below and you can see i have a file shown in the editor

enter image description here

And you can see I have a file queryFile which does not have any extension .

The command line results are fine .

Looks like the file does not need to enclose query in double quotes and thats your issue .

0
0

I just encountered this same issue and figured it out. Thought I would post here in case it helps someone in the future. In my case, the .soql file should not have anything other than the query text. All I needed to do was remove the comments in the file and everything worked fine. So, for example, with the default account.soql file that comes with a new sfdx project you just need to make the following changes.

Change this

// Use .soql files to store SOQL queries.
// You can execute queries in VS Code by selecting the
//     query text and running the command:
//     SFDX: Execute SOQL Query with Currently Selected Text

SELECT Id, Name FROM Account

To this

SELECT Id, Name FROM Account

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.