Salesforce Org to Org Opportunity Bidirectional Sync

โ˜…โ˜…โ˜…โ˜…โ˜…
(0 reviews)

home

Bidirectionally synchronizes opportunity data between two Salesforce Orgs. This template makes it fast to configure the fields to be synchronized, how they map, and criteria on when to trigger the synchronization. Parent accounts are created if they donโ€™t already exist in the destination org, or this template can be configured to link all opportunities created to a specific account.

This template can trigger either using our polling mechanism or can be easily modified to work with Salesforce outbound messaging to better utilize Salesforce API calls. This template uses watermarking to ensure that only the most recent items are synchronized and batch to efficiently process many records at a time.

1d25ac90-0cc6-4dce-8fa4-e484eae9f540-image.png

License Agreement

This template is subject to the conditions of the MuleSoft License Agreement. Review the terms of the license before downloading and using this template. You can use this template for free with the Mule Enterprise Edition, CloudHub, or as a trial in Anypoint Studio.

Use Case

As a Salesforce admin, I want to have my opportunities synchronized between two different Salesforce organizations.

Template Overview

To keep Salesforce instance A synchronized with Salesforce instance B, the integration behavior can be summarized with the following steps:

  1. Ask Salesforce A: What changes have there been since the last time I got in touch with you?
  2. For each of the updates fetched in the previous step (1.), ask Salesforce B: Should the update received from A be applied?
  3. If the Salesforce answer for the previous question (2.) is Yes, then upsert (create or update depending each particular case) B with the belonging change.
  4. Repeat previous steps (1. to 3.) the other way around (using B as source instance and A as the target one) -- Repeat ad infinitum.
  5. Ask Salesforce A: Which changes have there been since the question in the step 1.?

And so on...

As implemented, this Anypoint Template also leverages Outbound messaging.

The integration can also be triggered by an HTTP Listener defined in the flow that triggers the application and executes the batch job with received message from Salesforce source instance.

Outbound messaging in Salesforce allows you to specify that changes to fields within Salesforce that can cause messages with field values to be sent to designated external servers.

Outbound messaging is part of the workflow rule functionality in Salesforce. Workflow rules watch for specific kinds of field changes and trigger automatic Salesforce actions in this case sending opportunities as an outbound message to the HTTP Listener, which further processes this message and creates an opportunity in a target Salesforce organization.

Considerations

To make this template run, there are certain preconditions that must be considered. All of them deal with the preparations in both, that must be made for the template to run smoothly. Failing to do so could lead to unexpected behavior of the template.

Salesforce Considerations

Here's what you need to know about Salesforce to get this template to work:

As a Data Source

If the user who configured the template for the source system does not have at least read only permissions for the fields that are fetched, then an InvalidFieldFault API fault displays.

java.lang.RuntimeException: [InvalidFieldFault [ApiQueryFault 
[ApiFault  exceptionCode='INVALID_FIELD'
exceptionMessage='Account.Phone, Account.Rating, Account.RecordTypeId, 
Account.ShippingCity
^
ERROR at Row:1:Column:486
No such column 'RecordTypeId' on entity 'Account'. If you are attempting to 
use a custom field, be sure to append the '__c' after the custom field name. 
Reference your WSDL or the describe call for the appropriate names.'
]
row='1'
column='486'
]
]

As a Data Destination

There are no considerations with using Salesforce as a data destination.

Run it!

Simple steps to get this template running.

Running On Premises

In this section we help you run this template on your computer.

Where to Download Anypoint Studio and the Mule Runtime

If you are new to Mule, download this software:

Note: Anypoint Studio requires JDK 8.

Importing a Template into Studio

In Studio, click the Exchange X icon in the upper left of the taskbar, log in with your Anypoint Platform credentials, search for the template, and click Open.

Running on Studio

After you import your template into Anypoint Studio, follow these steps to run it:

  • Locate the properties file mule.dev.properties, in src/main/resources.
  • Complete all the properties required as per the examples in the "Properties to Configure" section.
  • Right click the template project folder.
  • Hover your mouse over Run as.
  • Click Mule Application (configure).
  • Inside the dialog, select Environment and set the variable mule.env to the value dev.
  • Click Run.

Running on Mule Standalone

Update the properties in one of the property files, for example in mule.prod.properties, and run your app with a corresponding environment variable. In this example, use mule.env=prod.

Running on CloudHub

When creating your application in CloudHub, go to Runtime Manager > Manage Application > Properties to set the environment variables listed in "Properties to Configure" as well as the mule.env value.

Once your app is all set and started, you need to define Salesforce outbound messaging and a simple workflow rule. This article shows you how to accomplish this

The most important setting here is the Endpoint URL which needs to point to your application running on CloudHub, for example http://yourapp.cloudhub.io:80/?source=value. Value for source parameter could be A for source outbound messaging for organization A or B for organization B. Additionally, try to add just few fields to the Fields to Send to keep it simple for begin.

Once this all is done every time you make a change to an opportunity in a source Salesforce org, this opportunity is sent as a SOAP message to the HTTP endpoint of running application in CloudHub.

Deploying a Template in CloudHub

In Studio, right click your project name in Package Explorer and select Anypoint Platform > Deploy on CloudHub.

Properties to Configure

To use this template, configure properties such as credentials, configurations, etc.) in the properties file or in CloudHub from Runtime Manager > Manage Application > Properties. The sections that follow list example values.

Application Configuration

HTTP Connector Configuration

  • http.port 9090

Batch Aggregator Configuration

  • page.size 200

Scheduler Configuration

  • scheduler.frequency 10000
  • scheduler.startDelay 0

This are the milliseconds (also different time units can be used) that will run between two different checks for updates in Salesforce

  • watermark.default.expression 2018-08-25T11:00:00.000Z This property is an important one, as it configures what should be the start point of the synchronization. The date format accepted in Salesforce Query Language is either YYYY-MM-DDThh:mm:ss+hh:mm or you can use Constants. More information about Dates in Salesforce

Trigger policy(push, poll)

  • trigger.policy poll

This property defines, which policy should be used for synchronization. When the push policy is selected, the HTTP inbound connector is used for Salesforce's outbound messaging and polling mechanism is ignored.

Account sync policy(empty value, syncAccount)

  • account.sync.policy

If the account.sync.policy property has no value assigned, the contact moves over without a parent account.

If the syncAccount policy is syncAccount, then the opportunity is created with an account with the same name as in the source instance.

SalesForce Connector Configuration for Company A

  • sfdc.a.username sfdc.a.user@mail.com
  • sfdc.a.password passworda
  • sfdc.a.securityToken avsfwCUl7apQs56Xq2AKi3X
  • sfdc.a.url https://login.salesforce.com/services/Soap/u/43.0
  • sfdc.a.integration.user.id A0ed000BO9T

Note: To find out the correct sfdc.a.integration.user.id value, refer to the example project Salesforce Data Retrieval in Anypoint Exchange.

SalesForce Connector Configuration for Company B

  • sfdc.b.username sfdc.b.user@mail.com
  • sfdc.b.password passwordb
  • sfdc.b.securityToken ces56arl7apQs56XTddf34X
  • sfdc.b.url https://login.salesforce.com/services/Soap/u/43.0
  • sfdc.b.integration.user.id B0ed000BO9T

Note: To find out the correct sfdc.b.integration.user.id value, refer to the example project Salesforce Data Retrieval in Anypoint Exchange.

API Calls

Salesforce imposes limits on the number of API calls that can be made. Therefore calculating this amount may be an important factor to consider. The template calls to the API can be calculated using the formula:

1 + X + X / ${page.size}

X is the number of Opportunities to be synchronized on each run.

Divide by ${page.size} because, by default, opportunities are gathered in groups of ${page.size} for each Upsert API call in the commit step. Also consider that this calls are executed repeatedly every polling cycle.

For instance if 10 records are fetched from origin instance, then 12 API calls are made (1 + 10 + 1).

When the outbound messaging is enabled in Salesforce and template trigger policy is push, specify the Salesforce source organization for example http://yourapp.cloudhub.io:80/?source=A as the URL query parameter.

Also consider that all required fields of opportunity in Salesforce should be added for the outbound messaging.

Customize It!

This brief guide provides a high level understanding of how this template is built and how you can change it according to your needs. As Mule applications are based on XML files, this page describes the XML files used with this template. More files are available such as test classes and Mule application files, but to keep it simple, we focus on these XML files:

  • config.xml
  • businessLogic.xml
  • endpoints.xml
  • errorHandling.xml

config.xml

This file provides the configuration for connectors and configuration properties. Only change this file to make core changes to the connector processing logic. Otherwise, all parameters that can be modified should instead be in a properties file, which is the recommended place to make changes.

businessLogic.xml

This file holds the functional aspect of the template (points 2. to 4. described in the template overview). Its main component is a [Batch job][8], and it includes steps for both executing the synchronization from Salesforce instance A to Salesforce instance B, and the other way around.

endpoints.xml

This file should contain every inbound and outbound endpoint of your integration app. It is intended to contain the application API.

In this particular template, this file contains a couple flows that query salesforce for updates using watermark as mentioned before.

errorHandling.xml

This file handles how your integration reacts depending on the different exceptions. This file provides error handling that is referenced by the main flow in the business logic.


Reviews

Salesforce Org to Org Opportunity Bidirectional Sync doesn't have any reviews yet
TypeTemplate
OrganizationMuleSoft
Created byMuleSoft Organization
Published onJul 16, 2019
Asset overview

Asset versions for 2.1.x

VersionRuntime versionActions
2.1.34.1.2
2.1.24.1.1

Categories

Products
SalesforceNo values left to add
Pattern
Bi-Directional SyncNo values left to add