Salesforce Org to Org User Aggregation

(0 reviews)

home

Aggregates users 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. You can trigger this manually or programmatically with an HTTP call.

Users are sorted such that the user only in Org A appear first, followed by users only in Org B, and lastly by users found in both orgs. The custom sort and 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.

142bea72-dd20-452f-9185-e448f2fd5447-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

As a Salesforce admin I want to aggregate users from two Salesforce Instances and compare them to see which users can only be found in one of the two and which users are in both instances.

For practical purposes this Template will generate the result in the format of a CSV Report sent by mail.

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.

As implemented, it gets users from two instances of Salesforce, compares by the email address of the users, and generates a CSV file which shows users in A, users in B, and Users in A and B. The report is then emailed to a configured group of email addresses that you configure in the mule.*.properties file.

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 the mule.prod.properties file in the /src/main/resources/ folder and run your app with the corresponding environment variable to use it. To follow the 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 you should browse to: http://localhost:9090/generatereport and this creates a CSV report and sends it to the emails that you configure in the mule.*.properties file.

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.

Once your app is all set and started, supposing you choose as domain name sfdcuseraggregation to trigger the use case you just need to browse to http://sfdcuseraggregation.cloudhub.io/generatereport and the report will be sent to the emails that you configure in the mule.*.properties file.

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

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

SMTP Services Configuration

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

Email Details

  • mail.from exampleuser1@gmail.com
  • mail.to exampleuser2@gmail.com
  • mail.subject Salesforce Users Report
  • mail.body Users report comparing users from Salesforce Accounts
  • attachment.name OrderedReport.csv

API Calls

Salesforce imposes limits on the number of API Calls that can be made. However, we make API call to Salesforce only once during aggregation.

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 conducting the aggregation of data, comparing records and finally formatting the output, in this case being a report.

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

Aggregated results are sorted by source of existence:

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

These are transformed to CSV format. The final report in CSV format is sent to email addresses, that you configure in the mule.*.properties file.

endpoints.xml

This file provides the endpoint to start the aggregation. This Template has an HTTP Inbound Endpoint as the way to trigger the use case.

Trigger 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 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 will then route requests from your application domain URL to the endpoint.

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.


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