Broadcast changes to leads in Salesforce organization A to Salesforce organization B in real time. The detection criteria and fields to move are configurable. Additional systems can be added to be notified of the changes. Real time synchronization is achieved via rapid polling or outbound notifications.
This template creates the parent account and relates it to the lead being synchronized if it does not exist or can be configured to a static parent account for all leads being created.
This template uses Mule batching and watermarking capabilities to capture only recent changes, and to efficiently process large numbers of records.
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.
As a Salesforce admin I want to synchronize Leads between two Salesforce orgs.
This Anypoint template serves as a foundation for setting an online sync of Leads from one Salesforce instance to another. Every time there is new Lead or a change in an already existing one, the integration will poll for changes in Salesforce source instance and it will be responsible for updating the Lead on the target org.
Requirements have been set not only to be used as examples, but also to establish a starting point to adapt your integration to your requirements.
As implemented, this template leverages the Mule batch module.
The batch job is divided in Process and On Complete stages.
During the Input stage the template will go to the Salesforce Org A and query all the existing Leads that match the filter criteria.
During the Process stage, each Salesforce Lead is filtered depending on if it has an existing matching Lead in the Salesforce Org B.
The last step of the Process stage groups the Leads and create/update them in Salesforce Org B.
Finally during the On Complete stage the template logs output statistics data into the console.
To make this template run, there are certain preconditions that must be considered. All of them deal with the preparations in both source and destination systems, that must be made for the template to run smoothly. Failing to do so can lead to unexpected behavior of the template.
Here's what you need to know about Salesforce to get this template to work:
- Where can I check that the field configuration for my Salesforce instance is the right one? See: Salesforce: Checking Field Accessibility for a Particular Field.
- How can I modify the Field Access Settings? See: Salesforce: Modifying Field Access Settings.
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.
Simple steps to get this template running.
Running On Premises
Complete all properties in one of the property files, for example in the mule.prod.properties file in the /src/main/resources/ folder and run your app with the corresponding environment variable to use it. To follow the example, use the
Once your app is all set and started, there is no need to do anything else. The application polls Salesforce to know if there are any newly created or updated objects and synchronizes them.
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
Mule Application (configure).
- Inside the dialog, select Environment and set the variable
mule.envto the value
Running on Mule Standalone
Update the properties in one of the property files, for example in the mule.prod.properties file, and run your app with a corresponding environment variable. In this example, use
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, there is no need to do anything else. Every time a lead is created or modified, the template automatically synchronizes to Salesforce Org B as long as it has an email address.
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.
Note: The property owner.sync.policy can take any of the two following values:
- empty_value: If the property has no value assigned to it then the application does nothing to the lead and just moves the lead over.
- syncOwner: Tries to create the lead's owner if there is no occurrence in Salesforce instance B.
Salesforce Connector Configuration for Company A
Salesforce Connector Configuration for Company B
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 / 200
X is the number of leads to be synchronized on each run.
Divide by 200 because, by default, leads are gathered in groups of 200 for each Upsert API call in the commit step. Also consider that calls are executed repeatedly every polling cycle.
For instance if 10 records are fetched from origin instance, then 12 API calls will be made (1 + 10 + 1).
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:
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.
Functional aspect of the template is implemented on this XML, directed by a batch job that will be responsible for creations/updates. The several message processors constitute four high level actions that fully implement the logic of this template:
- Job execution is invoked from triggerFlow (endpoints.xml) every time there is new query executed asking for created or updated Leads.
- During the Process stage, each SalesForce Lead is filtered depending on if it has an existing matching Lead in the SalesForce Org B.
- The last step of the Process stage groups the Leads and create/update them in SalesForce Org B.
- Finally during the On Complete stage the template logs output statistics data into the console.
This file is conformed by two Flows.
The first one is the trigger flow. This one contains the Scheduler endpoint that will periodically trigger watermark flow and then executing the batch job process.
The second one is the watermark flow. This one contains watermarking logic to query Salesforce for updated or created leads that meet the defined criteria in the query since the last polling. The last invocation timestamp is stored by using Object Store component and updated after each Salesforce query.
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.