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

POST Request With SOQL Query Envelope

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, lets’ launch Postman API Client and follow the below steps-

The Request Object

Step 1. Select “POST” as the request type, since we are going 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 articles also “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.

POST Request With SOQL Query Envelope

Step 5. 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 and if no error encountered we should be able to see the response coming in

POST Request With SOQL Query Envelope

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 Id and Name of Lead coming in as part of the response object

POST Request With SOQL Query Envelope

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 as it will help me during code development involving SOAP Request

POST Request With SOQL Query Envelope

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 Salesforce API 

Step 12. Click “Save to Salesforce APIs” to save the request to the collection

POST Request With SOQL Query Envelope

Conclusion

POST Requests with SOQL Query Envelopes is 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.

Hope you enjoyed this article. Please leave your comments to let me know how you do like the content and how you do find it helpful to learn the topic.


Similar Articles