Salesforce and soapUI – Testing WebServices directly

In a previous post I talked about writing webservices for Salesforce. In this post I’ll discuss how to test your webservice with soapUI without having to write any additional code.

Getting soapUI

You will need to install the Open Source version of soapUI from their sourceforge.  Go ahead, I’ll wait….

Getting the WSDLs

Now that you have soapUI installed we need to download our WSDLs.  You’ll need the Enterprise WSDL which can be found at Setup-Develop-API.  And you’ll need the WSDL for your webservice which can be found at Setup-Develop-Apex Classes, then find your class and click the WSDL link next to it.  I suggest downloading them into a WSDL folder just for organization.

Setting up soapUI

Now that we’ve got all of our parts we need to create a new soapUI project.  If you are testing multiple webservices I suggest you only create one soapUI project and import the additional webservices into it.  This will make updating the enterprise WSDL easier, and will make your life less stressful.

Right-click on Projects and select New soapUI Project and fill out the form with your information.  Your intial WSDL should be the enterprise WSDL.  You will at the very least want to have Create Requests checked.  You can choose the other later if you want to.

After creating the new project you will see a section called SoapBinding with several methods below it.  These are standard Salesforce methods that are provided by the Salesforce Enterprise WSDL. Let’s ignore these for right now, and import our webservice.  To add a new WSDL right-click on the project name, Salesforce in our case, and select Add WSDL.

Then we want to choose our webservices WSDL

Using soapUI

Now that we are all setup, let’s test our webservice.  First we need to login to Salesforce and get our session Id.  Under the SoapBinding list, expand login and choose Show Request Editor.  After opening the request editor we need to remove the extra headers we don’t need, and fill in our username and password.

Then press the “play” button to send the request

Now in the resulting XML we can pull out our session Id

Copy the session Id and we will use it to make a request to our webservice.  In the example below I am calling the search method on my CaseAPI.  Again, we can remove almost all of the header out of the request.  The only section we need to leave is the SessionHeader and SessionId.

Then fill in the request to your webservice.  This will all depend on how yours is designed.  In the webservice call below, we pass in two context objects.  One takes in an ssoName and the other takes in a searchString.  Then as before click the “play” button and you’ll get your response back.

Conclusion

SoapUI is a great tool to help test webservices out.  You can use it to build up tests, but that’s another post.  I use it all of the time to verify that Salesforce is returning the correct data from my webservice instead of trying to write against the webservice and trying to determine if my client is messing up.

This entry was posted in Development, Salesforce and tagged , , , , , , . Bookmark the permalink.
  • Ladu kishore Dash

    Good one ,Very useful thanks Patrick for sharing this.

  • Patrick,

    Perhaps you’d like to share your experience using soapUI in the future as a guest blog for @SmartBear

    soapUI users group on Linkedin if you’re interested: http://www.linkedin.com/groups?home=&gid=4082922

    Best,
    Alex

  • Maulik

    Patrick,

    After copying the sessionId in my application, if I query lets say describeGlobal operation, I am getting following exception:

    UNKNOWN_EXCEPTION
    UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

    UNKNOWN_EXCEPTION
    Destination URL not reset. The URL returned from login must be set in the SforceService

    Based on docs, it seems we need to put serverUrl as well. Have you tried doing it? After putting it, I still dont get it.

  • I’ve not ever had to put in a ServerURL. I believe it uses the URL provided in your services WSDL. If you look in the last screenshot, mine has https://cs9-api.salesforce.com/ does yours have that?

  • Dhan

    Yes too face the same issue with SFDC API query method
    Here the exception :

    UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService

    In my query request i couldn’t make out any field like service url or destination url.

    Any inputs will be appreciated.

    Thanks
    Dhan

  • Pingback: Salesforce and soapUI – Using the default query method » Deadlypenguin()

  • I’ve written a new post about how to fix that issue.

  • Siddu

    Here is my code. Could you please let me know how to invoke this from soapUI or command prompt.

    When I try to call this from command prompt it is trowing an error that “Protocol https is not supported or disabled in libcurl”

    any help would be greatly appreciated.

    Thanks in advance.

    @RestResource(urlMapping=’/UpdateLead/*’)
    global class UpdateLeadRecord {
    @HttpPost
    global static boolean LeadRecordUpdateFromExSystem(String RecordId, String APIName, String FieldValue) {

    try
    {
    String LeadQuery = ‘Select id, ‘+ APIName + ‘ From Lead where id =: ‘+RecordId + ‘ limit 1’;

    Lead LeadRecord = Database.query(LeadQuery);

    //LeadRecord.APIName = FieldValue;

    //Object o = LeadRecord.get(APIName);
    LeadRecord.put(APIName, FieldValue);

    update LeadRecord;

    return true;
    }
    catch(Exception e)
    {
    return false;
    }

    }
    }

  • All the experience I have with soapUI is with SOAP webservices not with REST webservices. I would suggest posting your question / problem on either the Stackexchange site of the Salesforce developer forums.

  • Pingback: SFDC inbound web service test with SOAPUI | SalesForce.com IQ()

  • rf

    I am not getting Login request under soapbindings to get the session id.

    i have only the wsdl imported into the project. Please help me where i am missing.

    I am testing the webservice part, so i wrote a sample webservice using develper edition.

    below is my webservice class

    global class test_websrvc{

    webservice static string test_web(String name){
    return ‘Hello’+name ;
    }

    }

  • Which WDSL are you using as your base?

  • Jose Tlaseca

    Hello:

    Thanks for your post, it was very helpful.

    I have created a SOAP webservice. I need to expose that WS to a force.com site in order to make it public.

    How can I test it using SOAP UI? (There are no login and password)

  • This is an interesting problem. I’ll look into it and write a post specifically about using soapUI and WebServices exposed via site, but in the mean time you can probably glean enough information from here.

  • dcd

    How would you translate your two requests into ‘curl’ commands?

    It’s not clear using ‘curl’ how to get the enterprise wsdl into the picture.

  • sindoora

    hi.
    i’m using partner wsdl and generated a wsdl for apex class.i was unable to get session id

  • sindoora

    Thank you.It’s working
    can u please let me know how to override the output values.

  • I’m not certain what you are asking. The output values in SoapUI will be whatever is coming back from the webservice. Therefore make no sense to override.

  • Are you stuck at any particular step in the process?

  • Unfortunately there is not a good way to use curl to obtain the enterprise wsdl. You can download it directly from setup ⇒ ⇒ DevelopAPI. You may be able to automatically download the wsdl with something like CasperJs but that’s a little bit tricker

  • Paras Dhingra

    Excellent Post…. Thanks a ton… It saved me a lot of effort and time 🙂

  • Nageswara Reddy

    Excellent…………………… It’s helped me a lot

  • Nageswara Reddy

    Thanks Patrick……………………….It’s helped me aloat

  • YomTej

    I was following the steps above but got stuck at the Login step. I tried many times but kept getting an error. I found the issue. The endpoint URI that should be used is “https://www.salesforce.com/services/Soap/u/10.0” instead of what is in the screenshot above “https://test.salesforce.com/services/Soap/c/23.0”

  • Yes, If you generate your WSDL on a production instance, it will point to the main URI, not to the test URI. If you generate your WSDL from the sandbox, it will have the correct endpoint.

  • Eugene

    This is great.. Do you know how can I pass parameters to my WSDL? My WSDL is accepting a list of records..

  • Is this a custom WSDL or the standard Enterprise WSDL?

    If it is the standard WSDL, a previous post I made [1] may help you with that, you’ll just have to generate the field names correctly.

    If it is a custom WSDL, SoapUI should generate the full set of fields (with names) that you need to post when you generate the new endpoint from the WSDL. Otherwise it should be … where webServiceVariableName was declared in your WebService class.

    [1] http://blog.deadlypenguin.com/blog/2012/04/13/salesforce-and-soapui-using-the-default-query-method/

  • Ranveer Rathi

    Hello Sir ,

    I am using inner class as a parameter and all variable declared , So my problem is that i am not pass parameter in soap api.

  • Are your parameters generated when you generate the WSDL inside of SoapUI? If not, you’ll need to make sure that your inner class and all of the variables you want to be settable via SOAP are WebService instead of public. If this is already the case, I will need to see both the SOAP request automatically generated by SoapUI and the code that generates your WebService.

    You can feel free to continue the conversation here, or continue it on IRC in the #salesforce channel. There my nick is “pcon” http://wearedarylshaber.com/irc

  • Pingback: Salesforce and soapUI – Testing WebServices directly » Deadlypenguin | Tnimish's Blog()

  • James Loghry

    One thumb up.

  • J112123

    Thumb up!!!

  • sandeep varma

    the enterprise wsdl is not parsing can u help me out and with which extension we need save wsdl file

  • Once you generate the WSDL on the web interface you can just Save As. The file type name shouldn’t really matter but it is technically a .xml file.

    What error exactly are you getting when importing the WSDL?

  • LNA

    Thank you. It was very usefull

  • NewBie

    Nice article…but i keep getting the below issue. correct me if i am doing it all wrong: 1. dowloaded Enterprise WSDL 2. Used this in SOAP UI to test. 3. Credential same as i use for login to that application.. 4. Keeps failing with INVALID LOGIN. how shall i go about this.

  • This can be caused by a couple of problems.

    1) If you are trying to access a sandbox, you will need to make sure your URL at the top is to test.salesforce not login.salesforce
    2) If you are trying to access this from an IP that is not in your whitelisted domain then you will need to use password + token (without the + symbol) or by adding your current external IP address to your organizations trusted IPs. [1]
    3) It could be that you typo’d either your username, password or you have an old/incorrect token.

    [1] https://www.salesforce.com/developer/docs/api/Content/sforce_api_concepts_security.htm

  • Jason

    Thanks Patrick, it’s late at night a customers php developer is having problems and I’m happy I can test it’s not our service that’;s the problem thanks to this.

  • Pingback: Web services development on Salesforce » Deadlypenguin()

  • Sanchivan

    Hi Patrick,

    I was able to get the Session Id and make the call. But in the response what I am getting is just empty tags. Why is that? I expect two results and it puts two tags in the Response tag but there is nothing in there. In the Apex Class I am returning a List of Wrapper Class that I created in Apex. Thanks.

    Sanch

  • What is the full type of the wrapper class? The class must have the global modifier and all of the class variables must have the WebServices modifier. I’d recommend reading over this as well

    http://blog.deadlypenguin.com/blog/2015/03/09/web-services-development-salesforce/

  • VK

    Hello Patrick, Thank you for beautifully explaining this. can you explain how we can write test classes for SOAP webservice classes?

  • Are you asking about testing in Apex for unit tests or are you asking about testing in SOAPui for integration testing?

  • Mitesh Sura

    Great article for anyone starting to use SoapUI in conjunction to Salesforce. Would it be any different if we use “Partner WSDL” instead of enterprise?

  • The names of the methods _might_ differ, but they probably won’t. The login method would be the same. The overall method remains the same.

  • pradeep nethas

    Perfect …. it worked for me tooo…. hurry …

  • Nitin

    Hi,

    I am getting following error while logging in:

    LOGIN_MUST_USE_SECURITY_TOKEN: Invalid username, password, security token; or user locked out. Are you at a new location? When accessing Salesforce–either via a desktop client or the API–from outside of your company’s trusted networks, you must add a security token to your password to log in. To get your new security token, log in to Salesforce. From your personal settings, enter Reset My Security Token in the Quick Find box, then select Reset My Security Token.

  • If you are accessing the API outside of your trusted IP addresses, you must append your security token to the end of your password. For more information, read over this article.

    https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_concepts_security.htm

  • Oriol

    Great! Thanks for sharing!

  • Anjan PM

    Nageshwar, how did you get the Case WSDL and In the login, what is the organization ID and Portal ID?