Salesforce Org to Org Contact Aggregation

(0 reviews)

home

Aggregates contacts from multiple Salesforce organizations into a CSV file. This basic pattern can be modified to collect from more or different sources and to produce formats other than CSV.

This application is triggered by an HTTP call that can be used manually or programmatically. Contacts are sorted such that the contacts only in Org A appear first, followed by contacts only in Org B, and lastly by contacts found in both orgs. The custom sort or merge logic can be easily modified to present the data as needed. This template also serves as a base for building APIs using the Anypoint Platform.

Aggregation templates can be easily extended to return a multitude of data in mobile friendly form to power your mobile initiatives by providing easily consumable data structures from otherwise complex backend systems.

59dce7c3-ab96-4881-8e02-6dd2e2073055-image.png

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 administrator I want to aggregate contacts from two Salesforce instances and compare them to see which contacts can only be found in one of the two and which contacts are in both instances.

This template generates the result in the format of a CSV Report sent by email.

This template serves as a foundation for extracting data from two systems, aggregating data, comparing values of fields for the objects, and generating a report on the differences.

This template contacts from two instances of Salesforce, compares by the email address of the contacts, and generates a CSV file which shows contact in A, contact in B, and contacts in A and B. The report is sent by email to a configured group of email addresses.

Considerations

To make this template run, there are certain preconditions that must be considered. All of them deal with the preparations in both, that must be made for the template to run smoothly. Failing to do so can lead to unexpected behavior of the template.

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

Complete all properties in one of the property files, for example in mule.prod.properties and run your app with the corresponding environment variable to use it. To follow this example, use mule.env=prod.

After this, to trigger the use case you need to browse to the HTTP endpoint with the port you configured in your file. If this is, for instance, 9090 then browse to http://localhost:9090/generatereport and this creates a CSV report and sends it to the email addresses you set.

Where to Download Anypoint Studio and the Mule Runtime

If you are a newcomer to Mule, here is where to get the tools.

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

Complete all properties in one of the property files, for example in mule.prod.properties and run your app with the corresponding environment variable. To follow the example, this is mule.env=prod.

Running on CloudHub

While creating your application on CloudHub (or you can do it later as a next step), go to Runtime Manager > Manage Application > Properties to set the environment variables listed in "Properties to Configure" as well as the mule.env.

After you have your app running, if you chose as domain name sfdccontactaggregation to trigger the use case, browse to http://sfdccontactaggregation.cloudhub.io/generatereport and the report is sent to the emails you configured.

Deploying Your Template on 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 (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 9090

Salesforce Connector Configuration for Company A

  • sfdc.a.username bob.dylan@orga
  • sfdc.a.password DylanPassword123
  • sfdc.a.securityToken avsfwCUl7apQs56Xq2AKi3X
  • sfdc.a.url https://login.salesforce.com/services/Soap/u/42.0

Salesforce Connector Configuration for Company B

  • sfdc.b.username joan.baez@orgb
  • sfdc.b.password JoanBaez456
  • sfdc.b.securityToken ces56arl7apQs56XTddf34X
  • sfdc.b.url https://login.salesforce.com/services/Soap/u/42.0

SMTP Services Configuration

  • smtp.host smtp.example.com
  • smtp.port 587
  • smtp.user exampleuser@example.com
  • smtp.password ExamplePassword456

Email Details

  • mail.from exampleuser@example.com
  • mail.to woody.guthrie@example.com
  • mail.subject SFDC Contacts Report
  • mail.body Contacts report comparing contacts from SFDC Accounts
  • attachment.name OrderedReport.csv

API Calls

Salesforce imposes limits on the number of API calls that can be made. This template only makes one API call to Salesforce during aggregation.

Customize It!

This brief guide gives a high level idea 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

Configuration for connectors and configuration properties are set in this file. Even change the configuration here, all parameters that can be modified are in properties file, which is the recommended place to make your changes. However if you want to do core changes to the logic, you need to modify this file.

In the Studio visual editor, the properties are on the Global Element tab.

businessLogic.xml

The functional aspect of the template is implemented in this XML file, directed by a flow responsible of conducting the aggregation of data, comparing records and finally formatting the output, in this case being a report.

Using the Scatter-Gather component we are querying the data in different systems. After that the aggregation is implemented in a DataWeave 2 script using the Transform component.

Aggregated results are sorted by source of existence:

  1. Contacts only in Salesforce A
  2. Contacts only in Salesforce B
  3. Contacts in both Salesforce A and Salesforce B

The output is transformed to CSV format. The final report in CSV format is sent to the email addresses that you configured in the mule.*.properties file.

endpoints.xml

This is the file where you find the endpoint to start the aggregation. This template has an HTTP Listener as the way to trigger the use case.

Trigger Flow

HTTP Listener - 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 generatereport 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.

errorHandling.xml

This is the right place to handle 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.


Reviews

Salesforce Org to Org Contact Aggregation doesn't have any reviews yet
TypeTemplate
OrganizationMuleSoft
Created byMuleSoft Organization
Published onMar 18, 2020
Asset overview

Asset versions for 2.1.x

VersionRuntime versionActions
2.1.24.1.4
2.1.14.1.1

Categories

Products
SalesforceNo values left to add

Tags