I have noticed that force CLI query returns the result in alphabetically for example if i will write query as force query select name,id from account then it will return the result as id then name. is anyone having any work around to solve this problem.

C:\Users\User>force query select name,ID from account limit 3
 Id                 | Name
 00128000002imxIAAQ | GenePoint
 00128000002imxJAAQ | United Oil & Gas, UK
 00128000002imxKAAQ | United Oil & Gas, Singapore
 (3 records)

3 Answers 3


This is a known issue as of now (acknowledged by Dave Carroll from Salesforce). I also see your comment on this thread. The workaround suggested to dump the output into CSV/ JSON and use external tool such as 'q' worked fine for me.

So, you should do something like this

force query select name,ID from account limit 3 > account.csv
q -H -d, 'select name, ID from account.csv'
  • Hi we have tried this buts not working .. Commented Jul 27, 2016 at 7:19
  • I tried and it seems to work for me. Which OS/ platform are you trying this on? Commented Jul 27, 2016 at 7:23

There are some limits piping "force query" output to "q" (like relative column names), but if you avoid the it can be handy.

I whipped together the following script which pipes "force query" through "q".

if [ $# -lt 1 ]; then
    echo 1>&2 "usage: $0 soql-query"
    echo 1>&2 ""
    echo 1>&2 "does not handle dotted (relative) columns like 'owner.name'"
    exit 2

#collect the SOQL satement into an environment variable
export SOQL=$@

#name a temporary file
export TMPFILE=soql.$$.csv

#execute "force query" and redirect to the temporary file
force query "$SOQL" --format:csv > $TMPFILE

#replace "from tablename" with "from temporary-file-name"
export QQL=`echo $SOQL | sed "s/from.*$/from $TMPFILE/g"`

#execute q with our new query
q -H -d, "$QQL"

#clean-up after ourselves
rm -f $TMPFILE
force query select name,ID from account limit 3 | grep 001d | awk -F',' '{ printf "%s,%s\n", $1, $2 }' 

You must log in to answer this question.

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