Salesforce Org to Org User Bidirectional Sync

(0 reviews)

home

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.

36d9a368-4659-4c95-bed8-3a83618a75c7-image.png

âš  Your browser has cookies disabled. You must have all cookies enabled for video playback to work

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

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.

Considerations

Before running this template:

  1. 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.
  2. 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).
  3. 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.

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.

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

Application configuration
  • scheduler.frequency 10000 This is the milliseconds to run between two different checks for updates in either Salesforce instance.
  • scheduler.startDelay 0
  • watermark.default.expression 2018-02-25T11:00:00.000Z This 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.000Z is 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 2018-04-21T11:00:00.000Z).
  • page.size 1000
SalesForce Connector Configuration for Company A
  • sfdc.a.username jorge.drexler@mail.com
  • sfdc.a.password Noctiluca123
  • sfdc.a.securityToken avsfwCUl7apQs56Xq2AKi3X
  • sfdc.a.integration.user.id A0ed000BO9T Note: 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
  • sfdc.b.username mariano.cozzi@mail.com
  • sfdc.b.password LaRanitaDeLaBicicleta456
  • sfdc.b.securityToken ces56arl7apQs56XTddf34X
  • sfdc.b.integration.user.id B0ed000BO9T Note: 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: ['SOME_PROFILE_IN_A': 'SOME_PROFILE_IN_B', 'ANOTHER_PROFILE_IN_A': 'ANOTHER_PROFILE_IN_B']

  • sfdc.a.profile.id ['00e200000015oKF': '00e20000001UzDx']

This should be a map that associates a profile in Salesforce B with a profile in Salesforce A, for example: ['SOME_PROFILE_IN_B': 'SOME_PROFILE_IN_A', 'ANOTHER_PROFILE_IN_B': 'ANOTHER_PROFILE_IN_A']

  • sfdc.b.profile.id ['00e200000015oKF': '00e20000001UzDx']

The meaning of these properties is defined in the second consideration in the previous section.

Test Configuration

email.a.b 'test@test.com'

API Calls

Not relevant for this use case.

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. 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.

endpoints.xml

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.

errorHandling.xml

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.


Reviews

TypeTemplate
OrganizationMulesoft
Published by
MuleSoft Organization
Published onJun 15, 2019
Asset overview

Asset versions for 2.1.x

Asset versions
VersionActions
2.1.2

Tags