Blog

Get Our Latest Thoughts & Opinions

Salesforce to SAP event-driven integration with MuleSoft

  • Yurii Kostenko

To support various business processes, many organisations make use of a variety of systems and technologies. With our clients, we see this phenomenon: despite their best intentions, many companies end up isolating the tools and systems they depend on to support innovation and process automation. 

In order to create even further automation and efficiencies, companies also need to integrate and connect all of their tech stack to get more value out of each system they have. This can further reduce any existing manual tasks. Here are some examples we've encountered multiple times: 

  • Create a new order in System A when a new order is activated in System B; 
  • Updating shipment address of a customer in System A when a sales rep records this change in System B;
  • Change the delivery date in System A when customer order details were changed in System B.

These tasks require event-driven integration, yet for most companies, current IT architectures are not loosely coupled and are not designed for event processing.

To accomplish this, companies can leverage MuleSoft as an integration layer and Anypoint MQ for reliable messaging between these systems.

Now let's look at the business use-case that some businesses require the solution for. 

SAP, which manages orders and invoices, and Salesforce, which manages sales and new customer acquisition processes, are the two most commonly used systems by businesses. Once a salesperson activates the created order in Salesforce, this order and its details need to be created automatically in SAP as well.

In order to implement event-driven integration for this use case on a publish/subscribe model, Salesforce will publish platform events when an order is activated. Mulesoft API then subscribes to these events, and once the message is received, it will store this message in the topic of Anypoint MQ cloud messaging service to avoid any message loss. MuleSoft API then will read this message from the queue, transform the data and create a new Order record in SAP. Additional error handling can also be implemented in MuleSoft application.


To build this solution, the Salesforce Platform Event must be created, and then Salesforce Flow Builder can be used to create these events when the order is activated. These events will contain basic information about the Orders needed for the SAP system.

 

After that, MuleSoft can handle the rest. The next action in this solution is to create a MuleSoft application. This application will consist of 2 flows: the first one will listen to the events from Salesforce and store them in Anypoint MQ for future processing; the second flow will retrieve the message from a queue and create a new record in SAP.

With an out-of-the-box Salesforce connector, the “Subscribe Channel Listener” operation will be used to listen to the events published by Salesforce whenever the Order is activated. Then, the application transforms the received event data and publishes the message to Anypoint MQ queue:


The second flow of MuleSoft application starts with the Anypoint MQ Subscriber operation which listens to the messages published in the previous flow. 

Once the message is received, it is transformed by the application to prepare the payload for the next step - creating a new order in SAP. MuleSoft can integrate SAP systems with certified prebuilt SAP connectors for S/4HANA, Concur, SuccessFactors, BusinessObjects, and Hybris plus dozens of SAP integration templates to speed up development. 

This solution will use a simple Database connector to connect to SAP cloud database and create a new order in it.  Additionally, “Until successful” scope is added to the solution. This scope will try to re-connect to SAP database (in case of connection failure or any other transient failures) based on the amount of maximum retries and time in between configured until the outcome is successful or maximum retries is reached.


If all retries fail in “Until successful” scope, the application should handle the error so that the message is not lost. The “Choice” scope implements logic where it first resends the message back to the initial event queue for reprocessing, and if the error persists several times - the message is then sent to the dead-letter queue (another process / service will handle these messages).


All that is left to do is to deploy the Mule application to CloudHub or on-premise server. Once it is up and running, the test can be performed by creating and activating the Order in Salesforce, and then to check if the new Order is created in the SAP database as well.

I hope that this use-case overview and its solution gave you a better understanding of how MuleSoft can help with event-driven data integration between systems like Salesforce & SAP. 

If you want to see a demo of this solution, reach out to us for more information.

Get In Touch

Discover how Pexlify can create digital experiences that transforms and optimises your business with Salesforce.

Get Started