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:
- Create BizTalk project.
- Import WSDL from Salesforce
- Create helper class library
- Create a login() request with valid Username and Password – Login Orchestration
- Use SessionId and ServerUrl to call another API (in our case it will be a query()) to get data from Salesforce.
- Create query() request – QueryProcessOrchestration
- Submit that request to Salesforce Url.
- 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 @
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.
- Add a new orchestration and name it Login.odx.
- Fill login request from an embedded resource file.
- Add a newly configured port in the orchestration and name it SalesForceLoginPort. Select the existing port type – SaleforceIntegration.Sample.Soap type.
- Keep port direction as – “I’ll be sending a request and receiving a response”. And select “Specify Later” as port binding.
- We will import SforceService.BindingInfo.XML later imported in our BizTalk Application to create the physical ports.
- Add two messages of multi-part message types
- loginRequest – login object from XSD
- loginResponse – login response object from XSD
- Define two variables in orchestration parameter with OUT property, SessionId, and ServerUrl.
- 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):
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.
- Receive an XML message to activate this orchestration. Add a receive location to bind with it.
- 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.
- Add another send port to send query response message as an XML to any location on your local.
- Add two messages of multi-part message types
- QueryRequest – query request object from xsd
- QueryResponse – query response object from xsd
- Define two variables in the orchestration of type string, SessionId, and ServerUrl.
- Call login orchestration from this orchestration and fill SessionId and ServeUrl
- 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.
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