SAP to Salesforce Order Broadcast

home

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

This Anypoint Template should serve as a foundation for setting a migration of Orders from SAP to Salesforce.
​
Requirements have been set not only to be used as examples, but also to establish a starting point to adapt your integration to your requirements.
​
The integration is triggered by a Scheduler that receives the migration request periodically. Scheduler frequency and start delay are defined in minutes.
Filters for Orders are defined in properties.
If customer filter is not defined, then every order for all acconts are migrated by usage of BAPI_SALESORDER_GETLIST and BAPI_CUSTOMER_GETLIST.
If filter is defined, all orders for specific account are migrated by usage of BAPI_SALESORDER_GETLIST.
If specified, obtained orders are later filtered by Order status and by date (watermark.default.expression). Then all filtered orders are input for Business Logic which are transformed into Salesforce Orders and are passed to the Batch process.
Filter test is used to limit number of migrated records mainly for testing solution.
​The Orders are stored in Salesforce and there is a need to customize the standard Salesforce objects.
As implemented, this Anypoint Template leverages the Batch Module. The batch job is divided in Process and On Complete stages.
​
During the Process stage, for each Order from SAP new objects Account, Contract, Products, PricebookEntries, Order, OrderItems are created/updated in Salesforce.
​
Finally during the On Complete stage the Template will provide information about finished migration.

Considerations

To make this Anypoint Template run, there are certain preconditions that must be considered.
All of them deal with the preparations in both source (SAP) and destination (SFDC) systems, that must be made in order for all to run smoothly.
Failing to do so could lead to unexpected behavior of the template.
​
Before continue with the use of this Anypoint Template, you may want to check out this Documentation Page, that will teach you how to work
with SAP and Anypoint Studio.
​

Disclaimer

​
This Anypoint template uses a few private Maven dependencies from Mulesoft in order to work. If you intend to run this template with Maven support, you need to add three extra dependencies for SAP to the pom.xml file.

SAP Considerations

Here's what you need to know to get this template to work with SAP.

As a Data Source

The SAP backend system is used as a source of data. The SAP connector is used to send and receive the data from the SAP backend. The connector can either use RFC calls of BAPI functions and/or IDoc messages for data exchange, and needs to be properly customized per the "Properties to Configure" section.

Salesforce Considerations

Here's what you need to know about Salesforce to get this template to work:

As a Data Destination

This template makes use of the SapOrder field in the Order Object in Salesforce. Here is a short description on how SFDC define custom fields.
The template uses the SapOrder in order to have a reference between the entities in both systems. The idea is, once an entity is created in SFDC it’s decorated with an ID from the source system which will be used aftewards for the template to reference it.
You will need to create a new custom field in your Order entity in SFDC with the following name:
+ SapOrder
For instructions on how to create a custom field in SFDC plase check this link:
+ Create Custom Fields

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 value dev.
  • Click Run. In order to make this Anypoint Template run on Mule Studio there are a few extra steps that needs to be made.Please check this Documentation Page:​
  • Enabling Your Studio Project for SAP

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.

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

Application Configuration
+ scheduler.frequency 1
+ scheduler.startDelay 0
+ aggregator.size 100

Watermarking default last query timestamp
+ watermark.default.expression '"2018-10-13T03:00:59Z"'
​
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
​
Salesforce Connector configuration
+ sfdc.username bob.dylan@sfdc
+ sfdc.password DylanPassword123
+ sfdc.securityToken avsfwCUl7apQs56Xq2AKi3X
+ sfdc.pricebook.id sfdc_pricebook_id
+ sfdc.pricebook.standard.id sfdc_pricebook_standard_id
​
SAP Filter records
+ sap.customer.name Customername
+ sap.order.status Completed
​+ test true

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. For each Order migration are used query calls for Account, Contract, Order, Products, PricebookEntries, OrderItems
and one delete call for removing existing OrderItems. For inserting new Accounts and OrderItems performed (X / ${aggregator.size})
calls, where X is the number of Orders to be synchronized on each run and division by ${aggregator.size} is because, by default, Accounts and OrderItems
are gathered in groups of ${aggregator.size} for each Upsert API Call in the aggregation step.

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 Anypoint Template is implemented on this XML, directed by a batch job that will be responsible for creations/updates. The several message processors constitute high level actions that fully implement the logic of this Anypoint Template:
​
1. Job execution is invoked from endpointsFlow (endpoints.xml).
2. During the Process stage, each Account and Order are checked if they already exists in Salesforce.
3. Insert new Accounts into the Salesforce instance if there were not found in the previous step.
4. For those new Accounts insert Contracts into Salesforce.
5. Check every Product from Order if it exists in Salesforce and create it if it wasn't found. Also check PricebookEntry for every Product and add missing one.
6. Remove existing OrderItems for further updating Order.
7. Upsert Order and insert OrderItems into Salesforce.
​
Finally during the On Complete stage the Anypoint Template will provide information about finished migration.

endpoints.xml

This file is conformed by a Flow containing the Scheduler that will periodically query SAP for updated/created Accounts and Orders that meet the defined criteria in the query and then executing the batch job process with the query results.

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.

TypeTemplate
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onAug 23, 2019
Asset overview

Asset versions for 2.1.x

Asset versions
VersionActions
2.1.0