5

I'm trying to export accounts to a csv file using the Force.com CLI tool. I keep getting and Unexpected Token error.

$ force query SELECT Id, Name FROM Account format:csv

ERROR at Row:1:Column:35

unexpected token: :

The format command was demoed at Dreamforce during the developer keynote. I find it odd that the command would not be available 4 months later.

I have tried multiple ways of using format with similiar results. --format:csv [format:csv] etc. I even tried json.

I'm using the latest release of the CLI.

  • Have you tried putting the query in qotes? "SELECT Id, Name FROM Account" – Boris Bachovski Mar 5 '14 at 22:25
  • Yes I have as that was the way it was demoed as well. In the help on the CLI it however does not have the actual query in quotes. And the query itself works without quotes. – JRiffe Mar 5 '14 at 22:26
3

I don't see it in the source in query.go in the runQuery method:

func runQuery(cmd *Command, args []string) {
    force, _ := ActiveForce()
    if len(args) < 1 {
        ErrorAndExit("must specify a query")
    }
    var query = ""
    if args[len(args)-1] == "format:json" {
        query = strings.Join(args[:len(args)-1], " ")
    } else {
        query = strings.Join(args, " ")
    }
    records, err := force.Query(query)
    if err != nil {
        ErrorAndExit(err.Error())
    } else {
        if args[len(args)-1] == "format:json" {
            d, err := json.MarshalIndent(records, "", " ")
            if err != nil {
                ErrorAndExit(err.Error())
            }
            fmt.Println(string(d))
        } else {
            DisplayForceRecords(records)
        }
    }
}

It looks like it just handles the format:json arg, but it does specify csv in the help and you can see it in the help text in the query.go file as well.

Maybe whatever was demoed was in some separate branch or something. Hopefully it gets added in. I was just thinking of a use case. :)

If you want you can download the source and hack it yourself. Just blogged about that here. I can confirm that format:json works with that as expected - look very closely at the featured image on my blog. ;)

  • Thank you! I was looking at the source code myself and didn't see it. I thought maybe I might have missed something since it was in the Demo and I assumed it would have stayed or been improved upon in the code. I also figured that the format:json didn't work because it wasn't in the release version that I was working with. I can work around the feature not being there, but it is extra steps that I thought I could avoid based on the Dreamforce Demo. I will hop on over and check out your blog. – JRiffe Mar 6 '14 at 3:02
2
$ force query "SELECT Sales_Order__c, Name FROM Opportunity" --format:csv
2

I find it helpful to have the SOQL in a text file, and then use ` and cat to inject it into the command:

force query "`cat mysoql.txt`" --format:csv >myresults.csv 
0

The positional argument for the query result format after the query is deprecated as of v0.23.0.

force query now supports a standard option for --format (or -f):

force query --format csv 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.