Using soapUI with Salesforce to test standard and custom web services response

soapUI is most common tool available to test Soap based web services, it also has capability to test REST web services. soapUI can be used to test Partner WSDL, enterprise WSDL, Tooling API, Metadata API to study capability and response from Salesforce before writing any code in Java, C# or any other language. In this article we will see, how we can leverage this tool to test enterprise WSDL from Salesforce.

You can download latest version of soapUI from here.

The WSDL file defines the Web service that is available to you. Your development platform uses this WSDL to generate an API to access the Force.com Web service it defines. You can either obtain the WSDL file from your organization’s Salesforce administrator or you can generate it yourself if you have access to the WSDL download page in the Salesforce user interface. You can navigate to the most recent WSDL for your organization from Setup by clicking “Develop | API | Enterprise WSDL” and download it.

Create new soapUI project by navigating to “File | New soapUI Project“. Provide project name and address of WSDL file downloaded from Salesforce.

Create New SoapUI project
Create New soapUI project

Login to Salesforce using soapUI

In newly created project, navigate to “login” binding and double click on Request1.

soapUI Salesforce login binding
soapUI Salesforce login binding

It will open split panel, left side contains sample request and right side contains response. We will be provided with sample request and need to enter required arguments, in this case username and password. Once done, click on green arrow above left panel, you would be presented with response on right panel (as shown in below image).

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:LoginScopeHeader>
         <urn:organizationId></urn:organizationId>
         <!--Optional:-->
         <urn:portalId></urn:portalId>
      </urn:LoginScopeHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:login>
         <urn:username>user@jitendra.com</urn:username>
         <urn:password>SamplePassword</urn:password>
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>
soapUI response for Salesforce Login method
soapUI response for Salesforce Login method

copy “sessionId” and “serverURL” from response, as we will need it to test other methods.

Query Salesforce records using soapUI and SOQL

Now, open “query” soap binding from soapUI project menu and update URL with server URL returned in above login call.

Edit Endpoint URL of soapUI to query Salesforce record
Edit Endpoint URL of soapUI to query Salesforce record

Sample XML request in soapUI to get records using SOQL

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <urn:PackageVersionHeader>
         <!--Zero or more repetitions:-->
         <urn:packageVersions>
            <urn:majorNumber>1</urn:majorNumber>
            <urn:minorNumber>1</urn:minorNumber>
            <urn:namespace></urn:namespace>
         </urn:packageVersions>
      </urn:PackageVersionHeader>
      <urn:MruHeader>

      </urn:MruHeader>
      <urn:QueryOptions>
         <!--Optional:-->
         <urn:batchSize>50</urn:batchSize>
      </urn:QueryOptions>
      <urn:SessionHeader>
         <urn:sessionId>00DU000000 0Mpcl!AQ 4AQMh.Hk2</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:query>
         <urn:queryString>SELECT ID FROM Account</urn:queryString>
      </urn:query>
   </soapenv:Body>
</soapenv:Envelope>

Sample response from soapUI

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
   <soapenv:Header>
      <LimitInfoHeader>
         <limitInfo>
            <current>106</current>
            <limit>15000</limit>
            <type>API REQUESTS</type>
         </limitInfo>
      </LimitInfoHeader>
   </soapenv:Header>
   <soapenv:Body>
      <queryResponse>
         <result>
            <done>true</done>
            <queryLocator xsi:nil="true"/>
            <records xsi:type="sf:Account">
               <sf:Id>001U000001SxeQQIAZ</sf:Id>
            </records>
            <records xsi:type="sf:Account">
               <sf:Id>001U000001SxeQRIAZ</sf:Id>
            </records>
            <records xsi:type="sf:Account">
               <sf:Id>001U000001SxeRGIAZ</sf:Id>
            </records>
            <size>3</size>
         </result>
      </queryResponse>
   </soapenv:Body>
</soapenv:Envelope>

In same way, we can use any other standard or custom WSDL using soapUI.

Related posts