Search code examples
restsalesforcesoql

Error 400 on SOQL Query via REST


I'm trying to do a "select * from accounts" query on salesforce via their rest API and I'm getting an ERROR 400 Bad Request. All of my rest calls seem to be working but I can't introduce a query. Can someone take a look at the code and let me know what they think?

The value that getSOQLQuery() is returning is:

url/services/data/v28.0/query?q=select+*+from+Account

        HttpClient httpclient = new DefaultHttpClient();
        HttpGet   get       = new HttpGet(getSOQLQuery());
        System.out.println(getSOQLQuery());
        get.setHeader("Authorization", "OAuth " + auth.getAuthToken());
        get.setHeader("content-type", "application/json");

        HttpResponse result = httpclient.execute(get);
        String json = EntityUtils.toString(result.getEntity(), "UTF-8");

        JSONParser parser = new JSONParser();
        Object resultObject = parser.parse(json);


        Object obj = resultObject.toString();

        if(result.getStatusLine().getStatusCode() == 200) {
            resultSet = obj;
            System.out.println("DONE");
        }else{
            System.out.println("Error!");
                System.out.println(result);
        }

Thanks!


Solution

  • SOQL doesn't support select * you have to explicitly name the fields you want to query, e.g. select id,name from account. You can use the describe resource to find all the field names if you want to dynamically build the select list.

    Also if you examine the response body of the 400 response, there'll be a detailed error message.