I have submitted a simple query using the Force.com CLI like so:

will@mint ~ $ force bulk query CallRecord__c "select Account__c, CallFlow__c from CallRecord__c"
Query Submitted
To retrieve query status use
force bulk query status 750F0000002ok5PIAQ 751F0000004QRtfIAG

To retrieve query data use
force bulk query retrieve 750F0000002ok5PIAQ 751F0000004QRtfIAG

Seems simple enough, so I periodically checked its progress until it was completed:

will@mint ~ $ force bulk query status 750F0000002ok5PIAQ 751F0000004QRtfIAG
Id          751F0000004QRtfIAG
JobId           750F0000002ok5PIAQ
State           Completed
CreatedDate         2015-07-08T21:27:22.000Z
SystemModstamp      2015-07-08T22:02:10.000Z
NumberRecordsProcessed  11313805

But then when I try to retrieve the results, I get nothing:

will@mint ~ $ force bulk query retrieve 750F0000002ok5PIAQ 751F0000004QRtfIAG | tee out.txt

will@mint ~ $ cat out.txt

will@mint ~ $ 

Well, I guess not nothing, but a newline is not the expected results. Am I misunderstanding how bulk queries work, or am I just using force incorrectly?

3 Answers 3


There are three parts involved here:

  1. The AsyncApiJob Id - 750 keyprefix - The Job
  2. The AsyncApiBatch Id - 751 keyprefix - The Batch
  3. The AsyncApiQueryResult Id - 752 keyprefix - The Batch Result

You appear to have the first two parts, but not the AsyncApiQueryResult Id that will be used to retrieve the actual CSV.

In terms or raw bulk API calls you need to get the AsyncApiQueryResult Id with:

GET baseURI/job/750x00000000014/batch/751x00000000030/result

This will return XML that contains the AsyncApiQueryResult Ids for each batch.

<result-list xmlns="http://www.force.com/2009/06/asyncapi/dataload">

Then you can use this final Id to Get the actual CSV:

GET baseURI/job/750x00000000014/batch/751x00000000030/result/752x000000000F1

I'm aware your question was specifically about the Force.com CLI tool, but thought it might be useful to know about the AsyncApiQueryResult Ids. I'll see if I can figure out how this manifests in the CLI tool.

How are your Go skills? It looks like on line 124 it is calling getBulkQueryResults(args2, args3) to retrieve that batch results.

Then by line 162 it is extracting the bytes from the results ids.

I also found a merged pull request from the 30th of May by mickle00 - Support for force bulk query retrieve to retrieve multiple result files. Fixes #140 #173. Looks like it used to directly assign to 'data' using the first result Id. I suspect this might have broken something.

  • Thanks for your answer! Having been led to workbech.developerforce I'll just use that for now. Also thanks for mentioning it on the force github, maybe I'll be able to take some time to try to fix it. I'd love an excuse to learn Go :)
    – Will
    Jul 9, 2015 at 15:52
  • 1
    @Will Yikes, sorry about this! I issued that pull request, and it does appear I erroneously broke it! More info here: github.com/heroku/force/pull/173 but I've already issued a fix which can hopefully get merged into master soon. Sorry about this, and thanks for bringing it to my attention!
    – Mikey
    Jul 9, 2015 at 19:10
  • Thanks @Mikey, I'm getting by with the other tools for now, but would love to start using the CLI again! I'll keep an eye on the GitHub.
    – Will
    Jul 9, 2015 at 20:40
  • @Will I see Dave Carroll just merged my pull request into master! It doesn't look like the pre-compiled binary links have been updated yet, but if you download the source and follow the compilation instructions github.com/heroku/force#hacking you should be able to go back to using it. Sorry again.
    – Mikey
    Jul 9, 2015 at 20:59
  • 1
    @ Mikey Awesome thanks! No need to apologize, I really appreciate being able to use the tool at all! Thanks again.
    – Will
    Jul 9, 2015 at 21:01

As Daniel Ballinger's answer and the comments point out, there was a bug in the force cli.

But as of v0.23.0, there's a new --wait option for the bulk query command that let's avoid polling for the job to finish:

$ force bulk --wait query CallRecord__c "select Account__c, CallFlow__c from CallRecord__c" | tee out.txt

2023 Update

Using Salesforce CLI's new "SF" commands simplifies things a lot.


sf data query -q "SELECT Id FROM Account LIMIT 1" -b --wait 0

That query will return a message similar to this one:

Run "data query resume -i 7504N00000hfIhvQAE -o [email protected]" to get the latest status and results.

Monitor job completion status however you prefer. Once the job is complete, use this command to download all the results:

sf data query resume -i 7504N00000hfIhvQAE -r "csv" > myCsv.csv

Where "7504N00000hfINRQA2" is your job Id. The '-r "csv" > myCsv.csv' portion of this command pipes the results into a csv file.

Source: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_data_commands_unified.htm#cli_reference_data_query_resume_unified

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .