• Saravanan Ramaswamy
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
My json reponse is:
{
  "totalSize": 1,
  "done": true,
  "records": [
    {
      "attributes": {
        "type": "Account",
        "url": "/services/data/v56.0/sobjects/Account/0017E00001N4y8FAAA"
      },
      "Id": "0017E00001N4y8FAAA",
      "Name": "Green Ltd",
      "BillingPostalCode": "SEW23"
    }
  ]
}

Java method to read the value:
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) { response.append(inputLine);
}
in.close();
JSONParser parse = new JSONParser();
JSONObject jobj = (JSONObject) parse.parse(response.toString()); accId = (String) jobj.get("Id");

However I get value for accId = null.
I'm trying to query salesforce account using Httpget method in java but getting malformed query error 

My code snippet below:

HttpClient httpClient = HttpClientBuilder.create().build();
String uri = https://myinstance.salesforce.com/services/data/v56.0/query/?q=Select+Id+,+Name+,+BillingPostalCode+From+Account+Where+BillingPostalCode+=+'S80 2AY'+AND+Name+=+'Mini Market Ltd'";
HttpGet httpGet = new HttpGet(uri);
System.out.println("oauthHeader2: " + oauthHeader);
httpGet.addHeader(oauthHeader);
httpGet.addHeader(prettyPrintHeader);
// Make the request.
HttpResponse response = httpClient.execute(httpGet);


Error: Malformed query. I have tried to encode the url but it doesn't work. I used UrlEncoder.encode(query, 'UTF-8') - same result.
I need to query a record from account with below filter criteria:

Select Id, name, billingpostalcode from account where name = 'xyz account'

postman error