Salesforce Org to Org User Migration
home
Moves a large set of users from one Salesforce organization to another. You can trigger this manually or programmatically with an HTTP call.
Users are upserted so that the migration can be run multiple times without worrying about creating duplicates. This template uses batch to efficiently process many records at a time.
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 migrate users from one Salesforce organization to another one.
This template serves as a foundation for the process of migrating users from one Salesforce instance to another, being able to specify filtering criteria and desired behavior when a user already exists in the destination org.
As implemented, this template leverages the Mule batch module.
The batch job is divided in Process and On Complete stages.
The migration process starts by fetching all existing users that match the filter criteria from Salesforce Org A.
Each user's profile ID is mapped from SalesForce instance A to B, each profile ID from the left (source instance) maps to the one on the right (target instance). Only the users with the same profile ID as configured source ID are migrated.
The last step of the Process stage groups the users and create them in Salesforce Org B.
Finally during the On Complete stage the template outputs statistics data into the console and sends a notification email with the results of the batch execution.
Considerations
There are a couple of things you should take into account 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 a user has for manipulating data. Each Salesforce account has its own profiles. In this template is a processor labeled assignProfileId and Username to the User where to map your Profile IDs from the source account to the ones in the target account. Note that for the integration test to run properly, you should change the constant DEFAULT_PROFILE_ID in BusinessLogicTestIT to one that's valid in your source test organization.
- 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 user with 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, 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:
- 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.
- Can I modify the Field Access Settings? How? 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.
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 valuedev
. - 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
.
After this, to trigger the use case you just need to browse to the local HTTP endpoint with the port you configured in your file. If this is, for instance, 9090
then browse to: http://localhost:9090/syncusers
, which create a CSV report and sends it to the emails you set.
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, if you choose as domain name sfdcusermigration
to trigger the use case, browse to http://sfdcusermigration.cloudhub.io/syncusers
and the report will be sent to the emails you configured.
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
Starting Date e.g. 2017-12-13T03:00:59Z
- startingDate
2014-01-30'T'00:00:00.000'Z'
Batch Aggregator Configuration
- page.size
200
SalesForce Connector configuration for company A
- sfdc.a.username
bob.dylan@orga
- sfdc.a.password
DylanPassword123
- sfdc.a.securityToken
avsfwCUl7apQs56Xq2AKi3X
Profile ID from SalesForce instance A(source)
- sfdc.a.profile.id
00e200000015oKFAAY
SalesForce Connector configuration for company B
- sfdc.b.username
joan.baez@orgb
- sfdc.b.password
JoanBaez456
- sfdc.b.securityToken
ces56arl7apQs56XTddf34X
Profile ID from SalesForce instance B(target)
- sfdc.b.profile.id
00e20000001UzDxAAK
SMTP Services Configuration
- smtp.host
smtp.gmail.com
- smtp.port
587
- smtp.user
gmailuser
- smtp.password
gmailpassword
Mail Details
- mail.from
batch.user.migration%40mulesoft.com
- mail.to
your.username@youremaildomain.com
- mail.subject
Batch Job Finished Report
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 the number of Users to be synchronized on each run.
Divide by ${page.size} because, by default, users are gathered in groups of ${page.size} for each upsert API call in the commit step.
For instance if 10 records are fetched from origin instance, then 12 API calls are made (1 + 10 + 1).
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
Functional aspect of the template is implemented on this XML, directed by one flow responsible of executing the logic.
For the purpose of this particular template the mainFlow uses a batch job, which handles all the logic of it.
endpoints.xml
This file provides the inbound and outbound sides of your integration app.
This template has only an HTTP Listener as the way to trigger the use case.
Inbound Flow
HTTP Inbound Endpoint - Start Report Generation
${http.port}
is set as a property to be defined either on a property file or in CloudHub environment variables.- The path configured by default is
syncusers
and you are free to change for the one you prefer. - The host name for all endpoints in your CloudHub configuration should be defined as
localhost
. CloudHub routes requests from your application domain URL to the endpoint. - The endpoint is configured as a request-response since as a result of calling it the response is the total of users migrated and filtered by the criteria specified.
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.