SFDC Stop - Always the latest about Salesforce


Full Tutorial Series with videos, free apps, live sessions, salesforce consulting and much more.


Telegram logo   Join our Telegram Channel

Saturday 8 February 2020

How to connect to Salesforce using SOAP APIs ? SOAP UI Tutorial

Hello Trailblazers,

SOAP UI is a very popular API testing tool specially when we talk about SOAP APIs. So, in this tutorial, we're going to see how we can connect with Salesforce Org using SOAP UI and we will call a standard salesforce soap api and have a look at the response. If you want to learn about connecting with Salesforce using REST APIs you can have a look at this tutorial. So, let's begin:-

Download SOAP UI

You can download SOAP UI by going to https://www.soapui.org/downloads/soapui.html and you'll see the below screen:-


As you can see above, there are two options. For advanced testing, you can download SOAP UI Pro however, we're going to download SOAP UI Open Source for this tutorial. Just click on the green button and your download will start automatically. If not, you can also click on the click here link on the next page as shown below:-


Once you've downloaded SOAP UI, open the installer and follow simple steps to install SOAP UI. You can keep the settings as default as we don't need any specific configuration while installing SOAP UI. Once you've downloaded and installed SOAP UI, open that and you'll see a start page similar to as shown below:-


Salesforce Enterprise WSDL

So, you've downloaded and installed SOAP UI. The next step is to download enterprise wsdl file from your Salesforce Org. Go to setup and search for api and click on API under Integrations. You'll see the screen as shown below:-


Click on Generate Enterprise WSDL link and you'll see the below page:-


This page is showing the managed packages versions that are installed in your org that you want to use in SOAP API integration with Salesforce. As for this tutorial, we're not going to connect with any managed package so this doesn't matter to us. Click on the Generate button and you'll see an xml as shown below:-


Save this xml file in your system as you save any html page (Ctrl + S for windows) and that's all. Now it's time to create a new project in our SOAP UI and test a standard Salesforce SOAP API.

Connecting with Salesforce using SOAP UI

1. Open SOAP UI, go to the File menu and click on New SOAP Project.


2. You'll see a dialog as shown below:-


As you can see above, I have given the project name as:- SFDCStopOrg (you can give any name of your choice). In Initial WSDL field, I have selected the Enterprise WSDL file downloaded from my Salesforce Org. Click on OK button and a new project will be created and will be shown on the left hand side panel as shown below:-


As you can see above, there are a number of operations that we can perform in our Salesforce Org such as:- changing password, converting lead etc. using standard SOAP APIs that are available.

3. Login to Salesforce:- Before testing any operation, our first step as to login to salesforce as we did in case of REST APIs. Here also, we need to get a token to interact with our Salesforce Org. Out of the different operations that are available in the left panel, look out for login and click on the Request 1 available under that as shown below:-


You'll see an xml request shown on the right side with 4 fields that we can fill up namely:- organizationIdportalId in the header and usernamepassword in the body. We don't need to fill organization id and we don't have a customer portal too so you can simply remove the question marks (?) from these tags to make them empty and fill up the username between the urn:username tags and password appended with security token between the urn:password tags as shown below:-


If you don't know your security token you can simply go to user settings which you can find below your profile picture.


Click on settings and search for reset and you will find an option to reset your security token.


Click on Reset Security Token button and you'll receive a mail from Salesforce with a new security token that you can append with your password in the urn:password field. Once your login request is ready, click on the green play button to submit the request.


You can see the reponse of this request in the right panel as shown below:-


As you can see in the response above, there is a tag named sessionId that consist of the token which we need to use in all our API requests to Salesforce. Just above that there is another tag named serverUrl which is our server URL for making SOAP requests to Salesforce Org. Copy this session id and server url and let's open another request to fetch data from Salesforce. 

Executing a Query using SOAP UI

Let's have a look at the below request in which I am querying Accounts using SOAP UI. I selected the Request 1 under the query operation from the left hand sidebar. The server URL which we got from login request is set in the address bar and the session id is set between the request xml urn:sessionId tag. You can see that I have commented some of the tags as they were not required for our operation. I have specified the query as:- SELECT Id, Name FROM Account between the urn:queryString tag as shown in the below image.


Submit the request using the green play button and you'll get a response as shown on the right hand side in the image above. You can see that I am receiving the id and name of accounts in the response xml as queried from Salesforce.

Congratulations..!! You've successfully connected with Salesforce using SOAP UI and fetched a list of accounts using the standard SOAP API available for executing query. In the same way, we can add a wsdl to the same project for a custom SOAP API that we can create in Salesforce using apex and test the same. The server URL will be already present in that case when we import a custom API wsdl. That's all for this tutorial, if you liked it, make sure to share it among your network and let me know your feedback in the comments down below.

Tired of reading or just scrolled down, don't worry, you can watch the video too.



P.S.:- If you want to learn Salesforce Integration, check out:- Salesforce Integration Tutorial Series.

Happy Trailblazing..!!

6 comments:

  1. Thanks Rahul, it helped me

    ReplyDelete
    Replies
    1. Happy to know that Suresh. Do share it in your network too :-)

      Delete
  2. Very helpful video Mr. Rahul but i try using mine says Unknown error while given my username and password along with security token could you please tell my what I did wrong

    ReplyDelete
    Replies
    1. Hi, if you can share some more information about the error, then only I'll be able to figure it out.

      Delete