Bidirectionally synchronizes user data between two Salesforce orgs. This template makes it fast to configure the fields to synchronize, how they map, and criteria on when to trigger the synchronization.
This template can trigger either using the Mule polling mechanism or 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.
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.
This template serves as a foundation for setting an online bi-directional sync of Users between two Salesforce instances with ability to specify filtering criteria.
This template fetches data for new or modified users using scheduler or the HTTP component. The changes that are fetched occurred in any of the Salesforce instances during a defined period of time. For those users who have not been updated yet, the integration triggers an upsert (update or create depending the case) using the last modification as the one that should be applied.
Before running this template:
- Users cannot be deleted in Salesforce: For now, the only thing to do regarding users removal is disabling or deactivating them, but this won't make the username available for a new user.
- Each user needs to be associated to a profile: Salesforce's profiles are what define the permissions the user has for manipulating data and other users. Each Salesforce account has its own profiles. Check out the next section to define a map between Profile IDs (from the source account to the ones in the target account and the other way around).
- Working with sandboxes for the same account: Although each sandbox should be a completely different environment, usernames cannot be repeated in different sandboxes. For example, if you have a username bob.dylan in sandbox A, you cannot create another user with username bob.dylan in sandbox B. If you are indeed working with sandboxes for the same Salesforce account, you need to map the source username to a different one in the target sandbox, for this purpose, refer to the processor labeled assign ProfileId and Username to the User.
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
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
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 mule.prod.properties, 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.
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.
10000This is the milliseconds to run between two different checks for updates in either Salesforce instance.
2018-02-25T11:00:00.000ZThis property is an important one, as it configures what should be the start point of the synchronization. If the use case includes synchronization of every user created from the beginning of time, use a date previous to any user creation (perhaphs
1900-01-01T08:00:00.000Zis a good choice). If you want to synchronize the users created from now on, then you should use a default value according to that requirement (for example, if today is April 21, 2018 and 11 AM in London, then you could use the following value
SalesForce Connector Configuration for Company A
A0ed000BO9TNote: To find out the correct sfdc.a.integration.user.id value, refer to the Salesforce Data Retrieval example project.
SalesForce Connector Configuration for Company B
B0ed000BO9TNote: To find out the correct sfdc.b.integration.user.id value, refer to the Salesforce Data Retrieval example project.
Salesforce's profiles define the permissions a user has for manipulating data.
Each Salesforce account has its own profiles.
This should be a map that associates a profile in Salesforce A with a profile in Salesforce B, for example: ['SOMEPROFILEINA': 'SOMEPROFILEINB', 'ANOTHERPROFILEINA': 'ANOTHERPROFILEINB']
This should be a map that associates a profile in Salesforce B with a profile in Salesforce A, for example: ['SOMEPROFILEINB': 'SOMEPROFILEINA', 'ANOTHERPROFILEINB': 'ANOTHERPROFILEINA']
The meaning of these properties is defined in the second consideration in the previous section.
Not relevant for this use case.
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.
This file holds the functional aspect of the template. Its main component is a batch job, and it includes steps for both executing the synchronization from Salesforce A to Salesforce B, and the other way around.
This file should contain every inbound and outbound endpoint of your integration app.
In this particular template, this file contains a scheduler endpoint that query Salesforce A and Salesforce B for updates using watermark and http endpoint for push operation.
This is the right place to handle how your integration will react depending on the different exceptions.
This file holds a Error Handling that is referenced by the scheduler flow in the endpoints xml file.