Salesforce SOAP API - POST Request With SOQL Query Envelope [Standard SObjects]

Introduction 

 
Executing SOQL Queries using SOAP API Requests possibly is one the most powerful implementation of Salesforce APIs and we can leverage it to customize database operations (CRUD) at the convenience of writing SOQL Queries.

In this article, we will discuss the detailed steps on executing SOQL queries for Standard Salesforce SObjects using SOAP API Query Envelopes.

To start with a demo, let's launch the Postman API Client and follow the below steps.
 

The Request Object


Step 1
 
Select “POST” as the request type, since we are going to provide the data to be submitted as part of the request so this is going to be a POST request to the Salesforce API Endpoint

Step 2
 
Specify the SOAP Service End Point, as mentioned in my earlier article: “https://<Domain Name>/services/Soap/c/<Version No.>”

Step 3
 
Select “raw” / “XML” as body content type. Specify the Session-Id for Request Authentication. You can receive this Id from the SOAP Login Request.

Step 4
 
Specify the SOQL Query to be executed to be part of the SOAP request. In this request, we are executing SOQL query to get details from the “Lead” (Standard Salesforce Object) and we specified “SELECT Id, Name FROM Lead”. We can specify any valid SOQL queries to execute and returned with results using the SOAP API.
 
Salesforce SOAP API - POST Request With SOQL Query Envelope [Standard SObjects]
 
Step 5
 
The next thing is to add Request Headers as we did in all other SOAP POST Requests.
  • “Content-Type”
    It will define that the request body will be in XML format

  • “SOAPAction”
    It will define the intent of the request. It is mandatory to include this header to the SOAP POST Request even if the value empty
With this, we are all set to submit the request.

Step 6
 
Click Send to submit the request. If no error is encountered, we should be able to see the response coming in.
 
Salesforce SOAP API - POST Request With SOQL Query Envelope [Standard SObjects]
 

The Response Object

 
Step 7
 
If we analyze the Response Object carefully, we will notice a lot of important pieces of information. Like we can see the current consumption(Current = 38) of API Requests and total allowed limit (limit = 15000) of API Requests execution
 
Step 8
 
We can also the collection of records from the “Lead” object. We can see the Id and Name of Lead coming in as part of the response object.
 
Salesforce SOAP API - POST Request With SOQL Query Envelope [Standard SObjects]
 
Step 9
 
If we scroll down to the bottom, we can see the size of the collection (size = 23) that gives us the count of records returned as a part of the response based on the SOQL query specified as a part of the SOAP Request.

As always, it is a good idea to save the request for later reference. I generally do this, as it will help me during code development involving SOAP Request.
 
Salesforce SOAP API - POST Request With SOQL Query Envelope [Standard SObjects]
 
Step 10
 
Specify the suitable name for the SOAP Request.

Step 11
 
Select the Postman Collection to save it request to. We already have a collection that we have created earlier. Refer to the Salesforce API.
Step 12
 
Click “Save to Salesforce APIs” to save the request to the collection
 
Salesforce SOAP API - POST Request With SOQL Query Envelope [Standard SObjects]
 

Conclusion

 
POST Requests with SOQL Query Envelopes are a very powerful implementation offered by Salesforce SOAP APIs. It is recommended not to use very complex queries as that might increase the processing time and might lead to request timeout issues with SOAP API Endpoint. So be intelligent which choosing your tools to deal with the specific problem statement.

I hope you enjoyed this article. Please leave your comments below to let me know how you enjoyed the content and how you found it helpful to learn the topic.