Sunday, October 17, 2021

How to write SOQL query in Java

In this post i will tell you how to write SOQL apex query in java. 


Before reading this post i will recommend you to go through Salesforce java integration post.
Variable baseUri in the code is basicallly your org's instance. To know more about how to get it refer my recommended post.

Java Code :

HttpClient httpClient = HttpClientBuilder.create().build(); String url = baseUri + "/services/data/v48.0/query?q=/services/data/v50.0/query?q=Select+id,name+from+account"; HttpGet httpGet = new HttpGet(url); httpGet.addHeader(oauthHeader); httpGet.addHeader(prettyPrintHeader); response = httpClient.execute(httpGet);

In java you have to use special character encoding to write the SOQL. Below are some of the examples for referance.

SOQL Apex : select id from account where name like '%d%'

SOQL Java : select+id+from+account+where+name+like+'%25d%25'

SOQL Apex : select id,name from account where name = 'Pyramid Construction'

SOQL Java : select+id,name+from+account+where+name+=+'Pyramid+Construction'


For metadata objects(Tooling api objects):


Tooling api objects are those which contain records in the form of metadata. You can query tooling api objects in java like below:

String url = baseUri +"/services/data/v52.0/tooling/query?q=+Select+id,Name+from+MetadataContainer"


Thanks, 
Lovesalesforceyes

No comments:

Post a Comment

Get selected radio button value in LWC

This post explains how to get selected radio button in LWC. Below is demo of output : To use the radio button in LWC you have to use the  li...