Site icon Salesforce News Technology Stuff

Use SoapUI to Test Salesforce WebService

In the SOAP API, Web Services Description Language (WSDL) file is basically used to understand how to use the API. We can use SoapUI to Test Salesforce WebService (Custom and Standard). While Salesforce provided Standard WSDL we can also generate our own custom API. But how we can test them as third party to make sure we will get expected results. So for this we can use SoapUI to Test Salesforce WebService.
Today we will cover how to generate SOAP to do Authentication and how we can consume our custom SOAP API.

Salesforce provides two SOAP API WSDLs for two different use cases. The enterprise WSDL is optimized for a single Salesforce org. It’s strongly typed, and it reflects our org’s specific configuration, meaning that two enterprise WSDL files generated from two different orgs contain different information.

The partner WSDL is optimized for use with many Salesforce orgs. It’s loosely typed, and it doesn’t change based on an org’s specific configuration.

Typically, if you’re writing an integration for a single Salesforce org, use the enterprise WSDL. For several orgs, use the partner WSDL.
So normally I prefer to use Partner as it it not depended and I can use same file to do Auth with different orgs.

1. Generate Partner API

So from Setup, enter API in the Quick Find box, then select API. On the API WSDL page, click Generate Partner WSDL.

2. Download and Setup SoapUI

You can download SoapUI from here. We can use SoapUI Open Source to test our WSDL. SoapUi Pro provide some advance function which you can use if needed.

3. Create Project in SoapUI

Now once we installed SoapUi, we are ready to create our first project. So first open the SoapUI tool. Click on File > New SOAP Project> It will open a modal. In the modal, give any suitable project Name and select the downloaded WSDL.

Note: Make sure Create sample requests for all operations remain checked. As it will create sample request.

4. Login Request to Get Access Token

So SoAPUI will create a new Project which have multiple sample request for different purpose. Scroll to login API and open the request. Here we will make oAuth request to get the session ID which we needed to make other requests.
So here we need to pass our usename and password + security token. In response will get sessionId, base URL and other details.

Keep this session Id handy as we need it to make request.

You can also test other API endpoints to do multiple task, including bulk data creation, updation, get user details etc.

5. Generate Custom WSDL in Salesforce

Create a Custom WSDL in Salesforce is very easy. We just need to use WebService class which have webservice method and we can generate WSDl from it. So for demo purpose I have used below class:

Sample Code
global with sharing class DemoSOAPWebService {
    webservice static Id makeContact(String contactLastName, String accountId) {
        Contact c = new Contact(lastName = contactLastName, AccountId = accountId);
        insert c;
        return c.id;
    }
}

So once you create Apex class in Salesforce. You will notice an option to Generate WSDL. Once downloaded, the steps to create project in SoapUI are same.

Finally we ready to consume our custom SOAP WSDL. We will pass all the required parameters with the session Id attribute.

Note: Remove all unnneccessary attributes else they will generate exception.

We can verify the created contact in system using the record Id.

6. Test Class for Custom WSDL

We can easily generate Test class for Custom WSDL. The steps are same as we create test class for any other class.

@isTest
private class DemoSOAPWebServiceTest {
    private static testMethod void positiveTest() {
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Id contactId = DemoSOAPWebService.makeContact('Test Contact', acc.Id);
        
        System.assert(contactId != null);
    }
}

Check the Lightning Web Components complete course here.

So Now we can easily create SOAP WSDL in Salesforce and can share with others. Do you have any questions, let me know in comments. Happy Programming 🙂

Exit mobile version