Salesforce SOAP Connector Example¶
The Salesforce SOAP Connector allows you to work with records in Salesforce, a web-based service that allows organizations to manage contact relationship management (CRM) data. You can use the Salesforce connector to create, query, retrieve, update, and delete records in your organization's Salesforce data. The connector uses the Salesforce SOAP API to interact with Salesforce.
What you'll build¶
This example explains how to use the Salesforce client to connect with the Salesforce instance and perform the create sObjects operation. Then execute a SOQL query to retrieve the Account Names in all the existing accounts. All operations are handled as SOAP messages.
-
Create an sObjects in Salesforce.
The user sends the request payload that includes sObjects (any object that can be stored in the Lightning platform database), to create a new Account object in Salesforce. This request is sent to the integration runtime by invoking the Salesforce SOAP connector API.
-
Execute a SOQL query to retrieve the Account Names in all the existing accounts.
In this example, the Salesforce Object Query Language (SOQL) is used to search stored Salesforce data for specific information created under
sObjects.
All two operations are exposed via a salesforce-soap-API API. The API with the context /salesforce has two resources
/createRecords: Create a newAccountobject in Salesforce./queryRecords: Retrieve the Account Names in all the existing accounts in Salesforce.

The user calls the Salesforce SOAP API. It invokes the createRecords resource and creates a new account in Salesforce. Then, through the queryRecords resource, it displays all the existing account details to the user.
If you do not want to configure this yourself, you can simply get the project and run it.
Set up the integration project¶
Follow the steps in create integration project guide to set up the integration project.
Add integration logic¶
First create an API to configure the integration logic. Select Micro Integrator and click on + in APIs to create a REST API. Specify the API name as salesforce-soap-API and API context as /salesforce.

Configure the createRecords resource¶
Now follow the steps below to add configurations to the resource.
-
Set up the salesforce.create operation.
-
Navigate into the Connectors pane and select the
createoperation under the Salesforce Connector section.
-
Click on the
Add new connectionbutton and replace theusername,password,loginUrlandblockingfields in the opened form with your values.- username: The username to access the Salesforce account.
- password: The password provided here is a concatenation of the user password and the security token provided by Salesforce.
- loginUrl : The login URL to access the Salesforce account.
- blocking : Indicates whether the connector needs to perform blocking invocations to Salesforce. (Supported in WSO2 ESB 4.9.0 and later.)
-
Setup the
createconfigurations.In this operation we are going to create a
sObjectsin the Salesforce account. AnSObjectrepresents a specific table in the database that you can discretely query. It describes the individual metadata for the specified object. Please find thecreateoperation parameters listed here.- sObjectName : XML representation of the records to add.
- allowFieldTruncate : Whether to truncate strings that exceed the field length (see Common Parameters).
- allOrNone : Whether to rollback changes if an object fails (see Common Parameters).
While invoking the API, the above three parameter values come as a user input.

-
To get the input values in to the API we can use the property mediator. Navigate into the Mediators pane and select the
Propertymediators .
The parameters available for configuring the Property mediator are as follows:
Note: The properties should be added to the pallet before creating the operation.
-
Add the property mediator to capture the sObject
Namevalue. In this example we are going to create a new Account object using the POST method.- name :
Name - expression :
//Name/text() - type :
STRING

- name :
-
Add the payload factory mediator to capture the sObject content.

-
Forward the backend response to the API caller.
When you are invoking the created resource, the request of the message is going through the
/createRecordsresource. Finally, it is passed to the Respond mediator. The Respond Mediator stops the processing on the current message and sends the message back to the client as a response.Select the respond mediator.
-
Configure the queryRecords resource¶
-
Set up the salesforce.query operation.
-
Setup the
queryconfigurations.In this operation we are going to retrieve data from an object, use
salesforce.queryand specify the following properties. If you already know the record IDs, you can use retrieve instead.- batchSize : The number of records to return. If more records are available than the batch size, you can use the queryMore operation to get additional results.
- queryString : The SQL query to use to search for records.
While invoking the API, the above two parameter values come as a user input.
-
Navigate into the Connectors pane and select
queryoperation listed under Salesforce Connector section.
-
To get the input values in to the API we can use the property mediator. Navigate into the Mediators pane and select the
Propertymediator. -
Add the property mediator to capture the sObject
queryStringvalue. In this example we are going to create a new Account object using the POST method.- name :
queryString - expression :
//queryString/text() - type :
STRING

- name :
-
Forward the backend response to the API caller.
When you are invoking the created resource, the request of the message is going through the
/createRecordsresource. Finally, it is passed to the Respond mediator. The Respond Mediator stops the processing on the current message and sends the message back to the client as a response.Select the respond mediator.
Now you can switch into the Source view and check the XML configuration files of the created API and sequences.
create.xml
<?xml version="1.0" encoding="UTF-8"?> <api context="/salesforce" name="salesforce-soap-API" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="POST" url-mapping="/createRecords"> <inSequence> <property expression="//Name/text()" name="Name" scope="default" type="STRING"/> <salesforce.init> <username>[email protected]</username> <password>eiconnectortestXXXnO9Nz4Qpiz5Us4N7ijj9zyA</password> <loginUrl>https://login.salesforce.com/services/Soap/u/42.0</loginUrl> <blocking>false</blocking> </salesforce.init> <payloadFactory media-type="xml"> <format> <sfdc:sObjects type="Account" xmlns:sfdc="sfdc"> <sfdc:sObject> <sfdc:Name>{$ctx:Name}</sfdc:Name> </sfdc:sObject> </sfdc:sObjects> </format> <args/> </payloadFactory> <salesforce.create> <allOrNone>0</allOrNone> <allowFieldTruncate>0</allowFieldTruncate> <sobjects xmlns:sfdc="sfdc">{//sfdc:sObjects}</sobjects> </salesforce.create> <respond/> </inSequence> <faultSequence/> </resource> <resource methods="POST" url-mapping="/queryRecords"> <inSequence> <property expression="//queryString/text()" name="queryString" scope="default" type="STRING"/> <salesforce.init> <username>[email protected]</username> <password>eiconnectortestXXXnO9Nz4Qpiz5Us4N7ijj9zyA</password> <loginUrl>https://login.salesforce.com/services/Soap/u/42.0</loginUrl> <blocking>false</blocking> </salesforce.init> <salesforce.query> <batchSize>200</batchSize> <queryString>{$ctx:queryString}</queryString> </salesforce.query> <respond/> </inSequence> <faultSequence/> </resource> </api>Get the project¶
-
You can download the ZIP file and extract the contents to get the project code.
Tip
You may need to update the value of the access token and make other such changes before deploying and running this project.
Deployment¶
In order to deploy and run the project, refer to the build and run guide.
Test¶
Invoke the API as shown below using the curl command. Curl application can be downloaded from here.
-
Create a new
Accountobject in Salesforce.Sample request
curl -v POST -d '<Name>Engineers</Name>' "http://172.17.0.1:8290/salesforce/createRecords" -H "Content-Type:text/xml"Expected Response
<?xml version='1.0' encoding='utf-8'?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com"> <soapenv:Header> <LimitInfoHeader> <limitInfo> <current>55</current> <limit>15000</limit> <type>API REQUESTS</type> </limitInfo> </LimitInfoHeader> </soapenv:Header> <soapenv:Body> <createResponse> <result> <id>0012x00000Am4kXAAR</id> <success>true</success> </result> </createResponse> </soapenv:Body> </soapenv:Envelope> -
Retrieve the Account Names in all the existing accounts in Salesforce.
Sample request
curl -v POST -d '<queryString>select id,name from Account</queryString>' "http://172.17.0.1:8290/salesforce/queryRecords" -H "Content-Type:text/xml"
You will get a set of account names and the respective IDs as the output.
What's next¶
- To customize this example for your own scenario, see Salesforce SOAP Connector Configuration documentation for all operation details of the connector.