Powered By Blogger

Sunday 1 December 2013

SOAPUI: Integration Helper for Salesforce

Recently I connected with hundred of developers. While taking to them, I felt that 75% of them were scared when it came to integration. So I thought to write this to make their life bit easier.

If you have a perfect WSDL file, which can be parsed easily in Saleforce, and you are the luckiest one. You can easily use generated wsdl classes for integrating Salesforce with other application. Picture starts when you have wsdl, but Salesforce is unable to parse it because of some constraints. 

Few common issues are:
  1. You have wsdl, but that is not in Salesforce supported format.
  2. You start modifying the wsdl to make it in Salesforce supported format, but it’s getting too hard and complex.
  3. Now you decide to go with HTTP request, but you don’t know the request body format.
  4. What you need to set in the request header?
  5. You have username and password, but you don’t know how to use that.
Please add your ones if I missed anything above.

SOAPUI: I would highly recommend downloading (http://www.soapui.org/Downloads/latest-release.html) and installing this tool. This allows you to create projects using WSDL files. When you create a project using wsdl, SOAPUI creates separate requests for each operation.

Creating a project in SOAPUI using wsdl

  1. Once you have been downloaded and installed SOAPUI, open soapui.
  2. Go to File -> New Project
  3. Choose your wsdl file and click on okay.
  4. You will see a new project is created in WSDL and it has all the operations.
  5. Select any operation and click on request1. It will show you complete request format.
  6. Now put your variables in request xml and hit the service.
  7. Click on Raw tab to see the request and response headers.
So now what you have all is:
EndPoint: As shown in screen-shot above
Method: Post
Content-Type: text/xml;charset=UTF-8
SOAP Action: As shown above
Request Body: As shown above

This is all enough to create your HTTP request in Salesforce and hit the endpoint. So how this will be implemented in Salesforce now:

You can create the requestBody string in Salesforce either by using the DOM class or you can also create a direct string like 
String requestBody = ‘<……..></…….>’;

//Request
HttpRequest request = new HttpRequest();
request.setEndpoint(endpoint);
request.setMethod(‘POST’);
request.setHeader('SOAPAction', soapAction);
request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
request.setBody(requestBody);

//Response
Http http = new Http();
HttpResponse response = http.send(request);

Now if you wish the parse the response, you can use DOM class to parse that.

If you have credentials and that need to be passed for authorization, then you can use these credentials in SOAPUI as given below:


In Salesforce this will be passed as :
Blob headerValue = Blob.valueOf(username + ':' + password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);

Please do not forget to leave your comments. It will help me to improve the quality in next.