Salesforce to Salesforce, Workday, SAP, and Database Account Broadcast
home
Synchronizes accounts between a Salesforce instance and many destination systems using the publish-subscribe pattern. Each time an account creates or changes, the integration polls for changes in the Salesforce source organization, publishes the changes to a topic, and each subscriber is responsible for updating the accounts in the target systems.
The application has four different batch jobs consuming this JMS topic, one each for broadcasting the changes to the four destination systems (the second Salesforce organization, Workday, SAP, and the database). During the Process stage, each Salesforce account is matched with an existing account in the destination system by name. The last step of the Process stage groups the accounts and creates or updates them in the destination systems.
Finally during the On Complete stage the template logs output statistics data to the console.
Read more about the publish-subscribe pattern in this blog post.
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 synchronize accounts from a Salesforce organization to another Salesforce organization, Workday, SAP, and Database instances.
This template serves as a foundation for setting an online sync of accounts from a Salesforce instance to many destination systems, using the Publish-subscribe pattern. Every time there is a new account or a change in an existing one, the integration polls for changes in the Salesforce source organization, publishes the changes to a topic, and each subscriber is responsible for updating the accounts in the target systems.
Requirements have been set not only to be used as example, but also to establish a starting point to adapt the integration to your requirements.
As implemented, this template leverages the Mule batch module. The batch job is divided into Process and On Complete stages.
The integration can be triggered in two different ways: by a scheduler defined in the endpoints file or by an outbound notification generated by Salesforce. Either way, the application queries or receives newest Salesforce updates or creates matching a filter criteria and adds them to a JMS topic.
The application has four different batch jobs consuming this JMS topic, one for migrating the changes to each target system (the second Salesforce Org, Workday, SAP and the database). During the Process stage, each Salesforce account is matched with an existing account in the target system by name.
The last step of the Process stage groups the accounts and create/update them in target systems.
Finally during the On Complete stage the template logs output statistics data into the console.
Considerations
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.
Note: The batch job fails if you do not provide correct value for Workday Customer Category ID. You need to extend the custom mapping, contained in "Transform Account To SubmitCustomerRequest Type" transformation, if accounts with more than five mapped Salesforce Industry or Workday Customer Category values are updated.
Database Considerations
This template uses date time or timestamp fields from the database to do comparisons and take further actions. While the template handles the time zone by sending all such fields in a neutral time zone, it cannot handle time offsets. (Time offsets are time differences that may surface between date time and timestamp fields from different systems due to a differences in each system's internal clock.) Take this into consideration and perform the actions needed to avoid the time offset.
As a Data Destination
There are no considerations with using a database as a data destination.
SAP Considerations
Here's what you need to know to get this template to work with SAP.
As a Data Destination
There are no considerations with using SAP as a data destination.
Salesforce Considerations
- 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 a user who configures 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.
Workday Considerations
As a Data Destination
There are no considerations with using Workday as a data destination.
Run it!
Simple steps to get this template running.
Run On Premises
In this section we detail the way you have to run your template on your computer.
After your app is all set and started, there is no need to do anything else. The application polls accounts to know if there are 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.
Run 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 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
.
Run 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
.
Run on CloudHub
While creating your application on CloudHub (or you can do it later as a next step), you need to go to Deployment > Advanced to set all environment variables detailed in "Properties to Configure" as well as the mule.env.
After your app is all set and started, there is no need to do anything else. Every time an account is created or modified, it is automatically synchronized to Salesforce organization B, Workday, SAP, and the database as long as the account matches the filtering criteria.
Deploy 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.port
8081
- page.size
200
- scheduler.frequency
60000
- scheduler.start.delay
0
- watermark.default.expression
2019-12-13T03:00:59Z
trigger.policy
push
Note: The
trigger.policy
property can assume only one of the values above as either push or poll.
Database Connector Configuration
- db.host
localhost
- db.port
3306
- db.user
mule
- db.password
mule
db.databasename
template-sfdc2sfdc.wday.sap.db-account-broadcast
Note: If you need to connect to a different database, provide its JAR file for the library, and change the value of that field in the connector.
Salesforce Connector Configuration for Company A
- sfdc.a.username
bob.dylan@orga
- sfdc.a.password
DylanPassword123
- sfdc.a.securityToken
avsfwCUl7apQs56Xq2AKi3X
Salesforce Connector Configuration for Company B
- sfdc.b.username
joan.baez@orgb
- sfdc.b.password
JoanBaez456
- sfdc.b.securityToken
ces56arl7apQs56XTddf34X
SAP Connector Configuration
- sap.jco.ashost
your.sap.address.com
- sap.jco.user
SAP_USER
- sap.jco.passwd
SAP_PASS
- sap.jco.sysnr
14
- sap.jco.client
800
sap.jco.lang
EN
sap.default.accountGroup
ZAG2
WorkDay Connector Configuration
- wday.username
username
- wday.tenant
tenant
- wday.password
ExamplePassword565
wday.host
services1.workday.com
category.biotechnology
CUSTOMER_CATEGORY-6
- category.financialServices
CUSTOMER_CATEGORY-1
- category.hospitality
CUSTOMER_CATEGORY-4
- category.manufacturing
CUSTOMER_CATEGORY-4-8
- category.technology
CUSTOMER_CATEGORY-5
- category.default
CUSTOMER_CATEGORY-5
A Category group defines CUSTOMER_CATEGORY_ID for each category as identified in Workday. The values are used for mapping Salesforce Account Industry field to Workday Customer Category.
If the category is not found between the specified industries, the category.default is used.
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} -- Where X is the number of accounts to synchronize on each run.
- Divide by ${page.size} because by default, accounts are gathered in groups of ${page.size} for each upsert API call in the commit step. Also consider that these calls are executed repeatedly every polling cycle.
For instance if 10 records are fetched from the 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
The business logic XML file creates or updates objects in the destination system for a represented use case. You can customize and extend the logic of this template in this XML file to more meet your needs.
endpoints.xml
This file contains:
- push flow - Contains an HTTP endpoint that listens for notifications from Salesforce. Each of notification is processed and thus updates or creates accounts, and then executes the batch job process.
- poll flow - Contains the Poll endpoint that periodically queries Salesforce for updated or created accounts that meet the defined criteria in the query, and then executing the batch job process.
- trigger.policy property - Defines from which endpoint the template receives the data. This property can only assume one of two values
push
orpoll
. Any other value results in the template ignoring all messages.
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.