Salesforce and S/4HANA Cloud Account Aggregation

(0 reviews)


This template aggregates (collects) accounts from Salesforce and S/4HANA Cloud into a CSV file. This basic pattern can be modified to collect from more or different sources and to produce formats other than CSV. The application can be triggered either manually or programmatically by an HTTP call. Accounts are sorted such that the accounts only in Salesforce appear first, followed by accounts only in S/4HANA Cloud, and lastly by accounts found in both systems. The custom sort or merge logic can be easily modified to present the data as needed. This template also serves as a great 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.

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.


To make this template run, there are certain preconditions that must be considered. All of them deal with the preparations in both source (SAP S/4HANA) and destination (SFDC) systems, that must be made for the template to run smoothly. Failing to do so can lead to unexpected behavior of the template.

Before you continue with the use of this template, you may want to check out this Documentation Page, that teaches you how to work with SAP S/4HANA and Anypoint Studio.

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

SAP S/4HANA Considerations

Here's what you need to know to get this template to work with SAP S/4HANA.

As a Data Destination

There are no considerations with using SAP S/4HANA 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, 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. After you import your template into Anypoint Studio, follow these steps to run it:
  • Locate the properties file, 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.To make this template run on Studio there are a few extra steps that needs to be made.Check this Documentation Page: Enabling Your Studio Project for SAP S/4HANA.

Running on Mule Standalone

Update the properties in one of the property files, for example in, 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

HTTP Connector Configuration

  • http.port 9090

Salesforce Connector Configuration

  • sfdc.username bob.dylan@sfdc
  • sfdc.password DylanPassword123
  • sfdc.securityToken avsfwCUl7apQs56Xq2AKi3X

SAP4HANA Connector Configuration

  • s4hana.baseUrl
  • s4hana.username your.sap4hana.username
  • s4hana.password your.sap4hana.password

SMTP Services Configuration

  • smtp.port 587
  • smtp.user
  • smtp.password ExamplePassword456

Email Details

  • mail.from
  • mail.subject SFDC and SAP S/4HANA Accounts Aggregation Report
  • mail.body Report comparing accounts from Salesforce and SAP S/4HANA Business Partners
  • AccountsReport.csv

API Calls

Salesforce imposes limits on the number of API calls that can be made. However, this template
only makes one API call to Salesforce 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


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.


The functional aspect of the template is implemented in this XML, directed by one flow responsible for conducting the aggregation of data, comparing records, and finally formatting the output as a CSV report.
Using the Scatter-Gather component, this template queries 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:

  1. Accounts only in Salesforce.
  2. Accounts (Business Partners) only in SAP S4HANA.
  3. Accounts (Business Partners) in both Salesforce and SAP S4HANA.

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


This is the file where you find the endpoint to start the aggregation. This template uses an HTTP Listener 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 as you prefer.
  • The host name for all endpoints in your CloudHub configuration is localhost. CloudHub then routes requests from your application domain URL to the endpoint.


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.


Salesforce and S/4HANA Cloud Account Aggregation doesn't have any reviews yet
Created byMuleSoft Organization
Published onNov 4, 2019
Asset overview

Asset versions for 2.1.x

VersionRuntime versionActions


SalesNo values left to add
AggregationNo values left to add
SalesforceSAPNo values left to add