Contact Free trial Login

Salesforce Composite Connector - Mule 4

Support Category: Select

Salesforce Composite Connector v2.3

Anypoint Connector for Salesforce Composite enables you to work with the Salesforce Batch and SObject Tree APIs. The connector exposes convenient methods for preparing subordinate requests, executing them in one batch, and parsing the results. Also it offers the posibility of creating SObject Trees through an operation separate from the batch ones, called createSobjectTree. This connector provides DataSense for preparing subordinate requests and parsing responses. DataSense is also provided for execution, and for creating SObject trees.

Prerequisites

To use this information, you should be familiar with Salesforce Composite, Mule runtime engine (Mule), Anypoint Connectors, Anypoint Studio, Mule concepts, elements in a Mule flow, and Global Elements.

You need login credentials to test your connection to your target resource.

POM File Information

<dependency>
  <groupId>com.mulesoft.connectors</groupId>
  <artifactId>mule-salesforce-composite-connector</artifactId>
  <version>RELEASE</version>
  <classifier>mule-plugin</classifier>
</dependency>

Mule converts RELEASE to the latest version. To specify a version, view Salesforce Composite Connector in Anypoint Exchange and click Dependency Snippets.

Connect in Design Center

  1. Click a trigger such as an HTTP Listener or Scheduler trigger.

  2. To create an optional global element for the connector, click Reusable Configurations. You can only use OAuth with username and password Authentication:

    Choose OAuth with Username and Password Authentication
  3. Select the plus sign to add a component.

  4. Select the connector as a component.

    Connector as a component
  5. Configure these fields for the Create SObject Tree operation:

    • SObject Root Type - The type of the root of the tree to be created.

    • SObject Tree - The entire structure of the tree to be created.

      Create SObject Tree operation

Required Parameters for the OAuth with Username and Password Configuration

  • Consumer Key - The consumer key for the Salesforce connected app.

  • Consumer Secret - The consumer secret for the connector to access Salesforce.

  • Username - The Salesforce username.

  • Password - The corresponding password.

  • Security Token - The corresponding security token.

    Design Center basic auth

Add the Connector to a Studio Project

Anypoint Studio provides two ways to add the connector to your Studio project: from the Exchange button in the Studio taskbar or from the Mule Palette view.

Add the Connector Using Exchange

  1. In Studio, create a Mule project.

  2. Click the Exchange icon (X) in the upper-left of the Studio task bar.

  3. In Exchange, click Login and supply your Anypoint Platform username and password.

  4. In Exchange, search for "composite".

  5. Select the connector and click Add to project.

  6. Follow the prompts to install the connector.

Add the Connector in Studio

  1. In Studio, create a Mule project.

  2. In the Mule Palette view, click (X) Search in Exchange.

  3. In Add Modules to Project, type "composite" in the search field.

  4. Click this connector’s name in Available modules.

  5. Click Add.

  6. Click Finish.

When Studio has an update, a message displays in the lower right corner, which you can click to install the update.

Configure in Studio

  1. Drag the connector to the Studio Canvas.

  2. To create a global element for the connector, set these fields:

    • OAuth with Username and Password Authentication:

      • Consumer Key - The consumer key for the Salesforce connected app.

      • Consumer Secret - The consumer secret for the connector to access Salesforce.

      • Username - The Salesforce username.

      • Password - The corresponding password.

      • Security Token - The corresponding security token.

        Studio basic auth

Use Case: Studio

  • Listener(HTTP) - Accepts data from HTTP requests.

  • Transform message - Transforms the HTTP input accordingly.

  • Salesforce Composite Connector - Connects with Salesforce and executes the create SObject tree operation.

  • Transform message - Outputs the results of the Create SObject tree operation in JSON format.

    Studio use case

Use Case: XML

Paste this XML code into Anypoint Studio to experiment with the flow described in the previous section.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:salesforce-composite="http://www.mulesoft.org/schema/mule/salesforce-composite"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
   xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
   http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core
http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/salesforce-composite
http://www.mulesoft.org/schema/mule/salesforce-composite/current/mule-salesforce-composite.xsd">
	<configuration-properties file="mule-app.properties"/>
	<http:listener-config name="HTTP_Listener_config"
   doc:name="HTTP Listener config">
		<http:listener-connection host="localhost" port="8081" />
	</http:listener-config>
	<salesforce-composite:composite-config name="Salesforce_Composite_Salesforce_Composite"
   doc:name="Salesforce Composite Salesforce Composite">
		<salesforce-composite:oauth-user-pass-connection
      consumerKey="${consumerKey}"
      consumerSecret="${consumerSecret}"
      username="${username}"
      password="${password}"
      securityToken="${securityToken}"
      tokenEndpoint="${tokenEndpoint}" />
	</salesforce-composite:composite-config>
	<flow name="salesforce-composite-create-sobject-trees">
		<http:listener doc:name="Listener"
      path="/createSObjectTree"
      config-ref="HTTP_Listener_config"/>
		<ee:transform doc:name="Transform HTTP input for Create SObject Tree">
			<ee:message>
				<ee:set-payload><![CDATA[%dw 2.0
output application/java
---
payload.records map ((record , indexOfRecord) -> {
	"attributes": {
		"type": record.attributes.objectType,
		"referenceId": record.attributes.referenceId
	},
	"Name": record.Name,
	"Phone": record.Phone,
	"Website": record.Website,
	"NumberOfEmployees": record.NumberOfEmployees as Number,
	("ChildAccounts": {
		"records": record.ChildAccounts.records map ((record01, indexOfRecord01) -> {
			"attributes": {
				"type": record01.attributes.objectType,
				"referenceId": record01.attributes.referenceId
			},
			"Name": record01.Name,
			"Phone": record01.Phone,
			"Website": record01.Website,
			"NumberOfEmployees": record01.NumberOfEmployees as Number
		})
	}),
	"Contacts": {
		"records": record.Contacts.records map ((record01, indexOfRecord01) -> {
			"attributes": {
				"type": record01.attributes.objectType,
				"referenceId": record01.attributes.referenceId
			},
			"LastName": record01.LastName,
			"Email": record01.Email,
			"Title": record01.Title
		})
	}
})
]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<salesforce-composite:create-sobject-tree
      doc:name="Create SObject tree"
      config-ref="Salesforce_Composite_Salesforce_Composite"
      type="Account"/>
		<ee:transform doc:name="Transform Message">
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
	</flow>
</mule>

Use Case: HTTP Input

An example of HTTP input for this flow is:

{
   "records":[
      {
         "ChildAccounts":{
            "records":[
               {
                  "Phone":"4321098765",
                  "Website":"www.salesforce.com",
                  "attributes":{
                     "objectType":"Account",
                     "referenceId":"ref5"
                  },
                  "NumberOfEmployees":"10",
                  "Name":"ChildAccount1"
               }
            ]
         },
         "Contacts":{
            "records":[
               {
                  "Email":"sample@salesforce.com",
                  "Title":"President",
                  "attributes":{
                     "objectType":"Contact",
                     "referenceId":"ref6"
                  },
                  "LastName":"Jones"
               }
            ]
         },
         "Phone":"9876543210",
         "Website":"www.salesforce.com",
         "attributes":{
            "objectType":"Account",
            "referenceId":"ref4"
         },
         "NumberOfEmployees":"101",
         "Name":"CreateSobjectTreeAccount2"
      },
      {
         "Contacts":{
            "records":[
               {
                  "Email":"sample@salesforce.com",
                  "Title":"President",
                  "attributes":{
                     "objectType":"Contact",
                     "referenceId":"ref2"
                  },
                  "LastName":"Smith"
               },
               {
                  "Email":"sample@salesforce.com",
                  "Title":"Vice President",
                  "attributes":{
                     "objectType":"Contact",
                     "referenceId":"ref3"
                  },
                  "LastName":"Evans"
               }
            ]
         },
         "Phone":"1234567890",
         "Website":"www.salesforce.com",
         "attributes":{
            "objectType":"Account",
            "referenceId":"ref1"
         },
         "NumberOfEmployees":"100",
         "Name":"CreateSobjectTreeAccount1"
      }
   ]
}

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.