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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

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

  • How to Convert XLS to XLSX in Java
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • Artificial Intelligence, Real Consequences: Balancing Good vs Evil AI [Infographic]
  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 user avatar
Abhishek Solanki
·
Aug. 10, 21 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
9.5K Views

Join the DZone community and get the full member experience.

Join For Free

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
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!