DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Kafka JDBC Source Connector for Large Data
  • How to Integrate a Distributed Database With Event Streaming
  • Read SAP Tables With RFC_READ_TABLE in Mule 4 Using SAP Connector
  • Amazon Dynamo DB Connector Operations Walkthrough in Mule 4, Part 1

Trending

  • The 20 Software Engineering Laws
  • Age Verification Is Becoming One of Tech’s Hardest QA Problems
  • Reading GC Logs: Memory Leak or Undersized Heap?
  • Telling a Language Model What a Fraud Ring Looks Like: A Snowflake Experiment

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Databases
  4. Merging Records in Salesforce Using Merge connector

Merging Records in Salesforce Using Merge connector

Let's take a look at why and how to use the salesforce merge connector provided by Mulesoft to Merge Records in Salesforce.

By 
Abhishek Solanki
·
Aug. 10, 21 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
10.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Introduction

The general work in Salesforce (SFDC) is doing the CRUD operation using Query, Delete, Create and Update (Upsert) operations.

I have found it difficult to find examples of how to merge requirements with Salesforce records. So in this article, I will explain, in detail, how to use the Salesforce Merge Connector.

Salesforce has provided 2 connectors for merging the salesforce records:

  1. Salesforce Merge Connector 
  2. Salesforce Merge Multiple Connectors

The version of the connector, other minimal support requirements, and Connector configuration is mentioned at this Mulesoft Documentation link. The salesforce Merge connector can merge up to 3 records in 1 record at a time in Salesforce. If more than 3 records are required to merge into 1 record then Merge Multiple Connectors needs to be used.

Following is the complete XML code for implementing the following requirement.

  1. Fetch the Salesforce Contact Object Id. (Master Record)
  2. Fetch the Salesforce Contact Object Id. (Child Record)
  3. Perform the Megre operation and Merge the Child record in Master Record.
XML
 
<?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:salesforce="http://www.mulesoft.org/schema/mule/salesforce"
	xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:anypoint-mq="http://www.mulesoft.org/schema/mule/anypoint-mq" 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/anypoint-mq http://www.mulesoft.org/schema/mule/anypoint-mq/current/mule-anypoint-mq.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/salesforce http://www.mulesoft.org/schema/mule/salesforce/current/mule-salesforce.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">
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="b67a5779-78ea-47e1-9e40-55c9aeb0fc8b" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<salesforce:sfdc-config name="Salesforce_Config" doc:name="Salesforce Config" doc:id="5f9a3188-bb45-4bdc-a6d5-5d2817d32766" >
		<salesforce:basic-connection username="username" password="Password" securityToken="security Toek" url="https://login.salesforce.com/services/Soap/u/51.0" />
	</salesforce:sfdc-config>
	<flow name="salesforce-merge-flow" doc:id="730bf513-d11e-45a1-8949-84d5fc4cc50a" >
		<http:listener doc:name="Listener" doc:id="758f2847-b011-42cd-a972-48e9f769fbe9" config-ref="HTTP_Listener_config" path="/getaccounts"/>
		<salesforce:query doc:name="Query" doc:id="5564195f-d11f-44af-a329-368348dee445" config-ref="Salesforce_Config">
			<salesforce:salesforce-query ><![CDATA[SELECT Id FROM Contact WHERE Name = 'Abhishek Solanki']]></salesforce:salesforce-query>
		</salesforce:query>
		<ee:transform doc:name="Transform Message" doc:id="df759e69-c1c8-4497-870b-e04537d5c77a" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
			<ee:variables >
			</ee:variables>
		</ee:transform>
		<set-variable value="#[payload.Id]" doc:name="Set Variable" doc:id="ac67dc6f-be24-4fad-81fa-e166a390d78a" variableName="contactId1"/>
	<salesforce:query doc:name="Query" doc:id="693c7fa4-28c9-4188-bedf-d2f643cd9fbc" config-ref="Salesforce_Config">
			<salesforce:salesforce-query ><![CDATA[select Id from Contact where Name='Meetup Demo Contact']]></salesforce:salesforce-query>
		</salesforce:query>
		<ee:transform doc:name="Transform Message" doc:id="b30adf8a-0343-4169-9bd6-427e49a21324" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
			<ee:variables >
			</ee:variables>
		</ee:transform>
		<set-variable value="#[payload.Id]" doc:name="Set Variable" doc:id="7cbac234-ce4f-4640-b702-b83f3d092aca" variableName="contactId2"/>
		<ee:transform doc:name="Transform Message" doc:id="673aeb9b-fe23-4e15-aad8-5257de6cfbcd" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/java
---
flatten([vars.contactId2])]]></ee:set-payload>
			</ee:message>
		</ee:transform>
		<salesforce:merge type="Contact" doc:name="Merge" doc:id="41ef54bb-1ede-4cda-b44a-9f12dac91ea3" config-ref="Salesforce_Config">
			<salesforce:master-record ><![CDATA[#[{
	Id: vars.contactId1[0]
}]]]></salesforce:master-record>
		</salesforce:merge>
		<ee:transform doc:name="Transform Message" doc:id="91477a6e-58e0-47bc-8846-cace5865682c" >
			<ee:message >
				<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
			</ee:message>
		</ee:transform>
</flow>
</mule>


The output will look like this: 

JSON
 
{
  "updatedRelatedIds": [
    
  ],
  "mergedRecordIds": [
    "0035g000009y2KkAAI"
  ],
  "success": true,
  "id": "0035g000009y1qgAAA",
  "errors": [
    
  ]
}

Note: All the salesforce record id which is being passed in the connector payload areas should be an array of string.

  1. The master record id can NOT be a part of Ids to merge. So you need to separate the master id and child ids for merging.
  2. The master id in the configuration should be provided as an object:

JSON
 
{
	Id: 'SFDC Object master record Id '
}

All complete details about the connector can be read at the link mentioned above.

Database Connector (mathematics) Merge (version control)

Opinions expressed by DZone contributors are their own.

Related

  • Kafka JDBC Source Connector for Large Data
  • How to Integrate a Distributed Database With Event Streaming
  • Read SAP Tables With RFC_READ_TABLE in Mule 4 Using SAP Connector
  • Amazon Dynamo DB Connector Operations Walkthrough in Mule 4, Part 1

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook