Testing the Force.com SOAP API Through SOAP UI Tool

Web Service Testing is one of the functional testing areas to test a specific application using different protocols. Generally, SOAP and REST are the two important protocols used to deliver the message and communicate with different systems with security.

Introduction about Web Service Testing 

Web Service Testing is one of the functional testing areas to test a specific application using different protocols. Generally, SOAP and REST are the two important protocols used to deliver the message and communicate with different systems with security.

Test Web Services with SOAP protocol  

Generally, SOAP protocol includes WSDL file in the XML format to send and receive the web service requests and responses. WSDL file describes the operation to perform offered by a web service. To test each operation, we can supply input values for the webservice and the output response can be generated.

Suppose if we need to test a Salesforce client application to which we have no direct access to create the records. With the help of SOAP UI tool, we can pass the message or we can create communication over the client application. Before start testing the application, we need to integrate the Salesforce application with the SOAP UI tool.

How to Integrate Salesforce with SOAP UI tool: 

As a client-side system admin, you can generate the WSDL by following these steps:

1.Click Set up and enter the API in the Quick Find box.

2.Click Generate Enterprise WSDL in API WSDL Page.

3.Click Generate button in Generate Enterprise WSDL page.

4.Once the File is generated in the XML format, right click the page and save it in the local drive.

5.Open the SOAP UI Tool.

6. Click New Project and paste the XML file in initial WSDL column.

7.Click ok Button.

soap api testing tool

In the left-hand side, SF Objects project appears to perform several actions.

soap api testing tool

We need to send the login request by exploring the login button. Then, press the “Request1”. In the request, we will replace the “?” with values for username and password lines.

soap api testing tool

Once the request is sent, the output is generated in the right-hand side window. Here, we need to capture the session id and server URL.

soap api testing

Scenario 1: To test a single Salesforce records for a single object using create () API

To send the create request for a single record, please copy and paste the below xml script into the left-hand side window.

XML script:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

  <soapenv:Header> 

    <urn:SessionHeader> 

      <urn:sessionId>Enter the session id </urn:sessionId> 

    </urn:SessionHeader> 

  </soapenv:Header> 

  <soapenv:Body> 

    <urn:create> 

      <urn:sObjects xsi:type="urn1:Enter the object name/API Name"> 

        <Enter the Field Name/API Name>enter the value </ Enter the Field Name/API Name > 

      </urn:sObjects> 

    </urn:create> 

  </soapenv:Body> 

</soapenv:Envelope> 

Test steps for the above scripts: 

1.Replace the session id by sending the login request.

2.Replace the “Enter the object name/API Name” with the object name for standard object. For custom objects, please enter the API name of the object.

3.Replace the “Enter the Field Name/API Name” with the field name for standard fields. For custom fields, please enter the API name of the field.

Scenario 2: To test multiple Salesforce records for two different objects using the create () API

To send the create request for multiple records for two different objects, please copy and paste the below XML script into the left-hand side window.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

  <soapenv:Header> 

    <urn:SessionHeader> 

      <urn:sessionId>Enter the session id</urn:sessionId> 

    </urn:SessionHeader> 

  </soapenv:Header> 

  <soapenv:Body> 

    <urn:create> 

      <urn:sObjects xsi:type="urn1: Enter the first object name/API Name ">  

        <Name>?</Name>  

        <department__c>?</department__C> 

        <date_of_joining>?</date_of_joining> 

        <test_checkbox__c>? </test_checkbox__c> 

        <Test_Lookup__c>?</Test_Lookup__c> 

      </urn:sObjects>  

      <urn:sObjects xsi:type="urn1: Enter the second object name/API Name ">  

        <FirstName>?</FirstName>  

        <LastName>? </LastName>  

      </urn:sObjects>  

    </urn:create>  

  </soapenv:Body>  

</soapenv:Envelope> 

Test steps: 

1.Replace the session id by sending the login request.

2.Replace the “Enter the first object name/API Name” with the object name for standard object. For custom objects, please enter the API name of the object.

3.For checkbox field, pass the Boolean value — either ‘1’,’True’ (or) ‘0’,’False’.

4.For date field and date/time field, please follow the either one of the below format.

FormatFormat SyntaxExample
Date onlyYYYY-MM-DD1999-01-01
Date, time, and time zone offsetYYYY-MM-DDThh:mm:ss+hh:mmYYYY-MM-DDThh:mm:ss-hh:mmYYYY-MM-DDThh:mm:ssZ1999-01-01T23:01:01+01:001999-01-01T23:01:01-08:001999-01-01T23:01:01Z

5.For picklist field, you can pass the active values as well as inactive values. If we want to restrict the inactive values, then we can change the Salesforce configuration to restrict picklist to the values defined in the value set.

6.For Lookup field, we need to create records for child to parent relationship. So, we need to pass the value as “Record id” of the parent.

6. Similarly, we can add the second object and field name by replace the “< Enter the second object name/API Name “> in the script.

7. Click the Request button.

8.Verify the success message in the right-hand side pane for the creation of records.

Below, I have provided the sample request to pass to the integrated Salesforce account.

soap api testing

Once the request is passed, we get an immediate response from the integrated salesforce account.

soap testing tools

How to save the request in the test case:

1.Click the “Add this request to a test case button”

soap testing tools

2.Choose the Test suite based upon the action we need to test (we can create new suite as well we can also add the test steps in the existing test suite)

soap testing tools

3.Let us create a new test suite named “Test suite-2”

soap testing tools

4.Then, create a test case number to perform the actions wherever necessary

soap testing tools

5.Finally, add the name of the Request to the test case

soap testing tools

6.Execute the test case in the Test Suite-2 named “Create two object records”

soap testing tools

Scenario 3: How to test by Querying the records using the query () API.

Sometimes, we come across business requirements for querying records from child-to-parent relationship objects. Let’s assume that the Department and Employee would be the parent and child objects available in the Salesforce account. So, I need to query child to parent relationship records. e.g. employee name, employee salary, department name, department description but records should be read only for IT department.

In the SOAP UI tool, please copy and paste the below xml script:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

  <soapenv:Header> 

    <urn:SessionHeader> 

      <urn:sessionId>Enter the session id </urn:sessionId> 

    </urn:SessionHeader> 

  </soapenv:Header> 

  <soapenv:Body> 

    <urn:query> 

      <urn:queryString>Enter the Query here </urn:queryString> 

    </urn:query> 

  </soapenv:Body> 

</soapenv:Envelope> 

Test Steps: 

1.Add the test steps to the test suite for query request.

2.Enter the query into the query response.

“select Name, Salary__c, Department__r. Name,Department__r.Description__c from Employee__c “

soap api testing

3.The output response shows the records with employee name, employee salary, department name, department description for IT department only.

soap api testing

Conclusion: 

With the help of SOAP UI tool, we can integrate client applications with salesforce to send the request for various API calls like insert, delete, update, upsert, query operations and manage each test cases with the help of test suite folder.

Reference Links: 

https://developer.salesforce.com/blogs/developer-relations/2015/06/salesforce-soap-api-sample-wsdls.html

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.