Biztalk Integration

Salesforce Integration using Microsoft BizTalk Server

In this blog, we will cover how to integrate any system with Salesforce (Salesforce CRM) using Microsoft BizTalk Server. This post includes a very simple scenario, get top 10 accounts from Salesforce. It will respond back with an XML and then you can tweak that XML as per your requirements.

Steps include to accomplish that scenario:

  1. Create BizTalk project.
  2. Import WSDL from Salesforce
  3. Create helper class library
  4. Create a login() request with valid Username and Password – Login Orchestration
  5. Use SessionId and ServerUrl to call another API (in our case it will be a query()) to get data from Salesforce.
  6. Create query() request – QueryProcessOrchestration
  7. Submit that request to Salesforce Url.
  8. Get back a response containing data.

Salesforce provides enterprise WSDL. If you have admin rights you can download it or please request Salesforce admin to download it for you.

Before moving any further, to clear concept how the web calls should be done we usually prefers to test those calls using SoapUI. You can find that in another blog post @

https://alliedc.com/sales-force-integration/

Let’s jump into Salesforce integration using BizTalk.

Import WSDL from Salesforce

Create an empty BizTalk project in Visual studio and import Salesforce WSDL in that project using the Web Service Consuming Wizard.

Once you have successfully imported that WSDL in your project you should be able to see imported objects as shown above.

After that go to SforceService_enterprise_soap_sforce_com.xsd schema and mark SessionId and ServerUrl for login response as promoted properties. We will be using these properties in our future steps to get those values from the response.

Create Login Orchestration – for request login data

This orchestration will be used to retrieve the session info after login. We will call this orchestration from another orchestration.

  1. Add a new orchestration and name it Login.odx.
  2. Fill login request from an embedded resource file.
  3. Add a newly configured port in the orchestration and name it SalesForceLoginPort. Select the existing port type – SaleforceIntegration.Sample.Soap type.
  4. Keep port direction as – “I’ll be sending a request and receiving a response”. And select “Specify Later” as port binding.
  5. We will import SforceService.BindingInfo.XML later imported in our BizTalk Application to create the physical ports.
  6. Add two messages of multi-part message types
    1. loginRequest – login object from XSD
    2. loginResponse – login response object from XSD
  7. Define two variables in orchestration parameter with OUT property, SessionId, and ServerUrl.
  8. Add Other shapes like below to complete the orchestration and configure them.

Construct msgLoginRequest as below (need to create a class library SalesforceSample.Helper.MessageHelper, referred below):

Orchestration parameters:

 

Expression to fill in SessionId and ServerUrl:

Create helper class library

A BizTalkHelper class is used to create various types of the message as XmlDocument. Method “CreateLoginRequestMessage” in this class reads the xml body from the XML template file added as an embedded resource in the project and then populates the placeholders for username and password and returns this XmlDocument.

Create Query Orchestration to Query Account data

This orchestration will be used to retrieve the Account information as XML. Id and Name of Accounts from Salesforce using login orchestration within. Add a new orchestration and name it ProcessAccountsQuery.odx.

  1. Receive an XML message to activate this orchestration. Add a receive location to bind with it.
  2. Add a newly configured port in the orchestration and name it SalesforceQueryPort. Select the existing port type – SaleforceIntegration.Sample.Soap type. Make this port dynamic. You will be sending a request and will receive a response from this port.
  3. Add another send port to send query response message as an XML to any location on your local.
  4. Add two messages of multi-part message types
    1. QueryRequest – query request object from xsd
    2. QueryResponse – query response object from xsd
  5. Define two variables in the orchestration of type string, SessionId, and ServerUrl.
  6. Call login orchestration from this orchestration and fill SessionId and ServeUrl
  7. Add Other shapes like below to complete the orchestration and configure them

Construct query message as below:

msgQuery.parameters =  SalesforceSample.Helper.MessagesHelper.CreateQueryRequestMessage();

msgQuery(WCF.OutboundCustomHeaders) = SalesforceSample.Helper.MessagesHelper.CreateTemplateHeaderMessage(SessionId);

SalesforceQueryPort(Microsoft.XLANGs.BaseTypes.Address) = ServerUrl;

SalesforceQueryPort(Microsoft.XLANGs.BaseTypes.TransportType) = “WCF-BasicHttp”;

msgQuery(WCF.SecurityMode) = “Transport”;

msgQuery(WCF.TransportClientCredentialType) = “None”;

msgQuery(WCF.Action) = “”;

You can send that query message to query() operation and then can receive query response. Once you have that query response you can utilize it as per your requirements or you can send that response as an xml file via send port to your local folder.

Conclusion:

In the same way, you can use any Salesforce API using the above-mentioned method. For more Salesforce soap API sample please visit Salesforce developer blog. You just need to modify those sample as per your requirement to test and validate them.

Author: Jahanzaib Khan

Senior Integration Consultant

[email protected]

Author

Hassan Askari