When I make a query using force command line on OS X, I can use backtick (`) and "cat" command to make the query contents come from a file, and this is very handy. Now I have switched to Windows and can't figure out how to do this in command line. Also I cannot use Powershell as IT won't allow that on our machines. Here is what I did in OS X:

force query "`cat myfile.soql`"

I can't seem to find the equivalent in Windows. Also there is the issue of multi-line parameters, and parameter length. I guess what I would love to see is query command switch to allow reading query from file, just as in the apex command.

  • That trick is a feature of the shell, not the program. However, I've made a note of this in case I get around to finishing my own cli.
    – sfdcfox
    May 5, 2016 at 2:25

1 Answer 1


Force CLI is open-sourced. Anyone can fork the repo.

File query.go is responsible for querying. It could be used as:

force query "select Id, Name, Account.Name From Contact"

But we want to pass file, e.g.:

force query file.txt

Line 47 joining query into single string and then passed to force.query method

soql := strings.Join(args, " ")
force.Query(fmt.Sprintf("%s", soql)

Lets try to read args[0] as file and assign it to soql string. Add before line 47 next code:

if _, err := os.Stat(args[0]); err == nil {
    var qyery []byte
    qyery, err = ioutil.ReadFile(args[0])
    args[0] = string(qyery)

Add libraries "io/ioutil" and"os" to import:

import (

That's it. You could compile it and use.

C:\Projects\Go\bin>echo select name, stagename from opportunity limit 2 > file.txt

C:\Projects\Go\bin>force query file.txt --format:csv

Prerequisites from link and Heroku github:

- Have Git installed on your computer.
- Make sure that you have The Go Programming Language installed. To make things simple, use the default installation path at `C:\Go`
- Make sure that you have Mercurial installed.
- Ensure the Go binaries (found in C:\Go\bin) are in your Path system environment variables.
- Create `C:\Projects\Go` with three folders: `bin/,pkg/,src/`
- Set the variable name to GOPATH and value to your Go workspace path (e.g. C:\Projects\Go)

# download the source and all dependencies

    $ go get -u github.com/heroku/force
    $ cd %GOPATH%/src/github.com/heroku/force

# provide your changes 
# to compile and test modifications:

    $ go get .
    $ cd C:\Projects\Go\bin
    $ force
  • there is login bug, go to version.go and change dev to dev1 May 6, 2016 at 4:42

You must log in to answer this question.

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