How to use LWC & Platform Event with MuleSoft?

0
897

 

Hello #Trailblazer #Mules,

In this blog post we are going to talk The Power of MuleSoft + LWC with Platform Event

Scenario

SFDCPanther is the whole seller of the parts of the heavy vehicles and the customer can reach out to Sales Rep to check if they are eligible for a discount or not.

Key points to Remember

  1. Sales Rep will be in Salesforce System
  2. Discount Details are available in a different Database
  3. The customer will be sitting on the Salesforce Digital Experience Site
  4. Sales Reps must need an Interface where they can enter Customer Identifier and Location to check the discount availability.
  5. SFDCPanther is concern about the security while making the call to an external database

Solution

The Salesforce Architect at SFDCPanther suggested using MuleSoft & Platform Event along with the LWC Component to achieve the solution.

Solution Approach

  1. Use JWT to connect with MuleSoft
  2. Create 2 Platform Event one for Making a call to External System using MuleSoft and the other for Salesforce to listen to the response from MuleSoft
  3. Create a Lightning Web Component to have the required input
  4. Publish the Platform Event using LWC
  5. Listen to the same event in MuleSoft, then make a Query to the database and publish the event from MuleSoft
  6. LWC will listen to the Event and display the message
  7. Test It

Setup Component at Salesforce Side

Step1 – Create Connected Application – Follow this link to create a connected application that supports JWT for authentication

Step2 – Create Platform Events

Login to Salesforce Org then navigate to

Setup -> Integrations -> Platform Events and Create 2 platform events. Below are the screenshots for the reference

Pricing Event – Published from LWC
Discount Event – Published from MuleSoft

Step3 – Create Lightning Web Component

You can get the Complete Code for the Lightning Web Component and Apex Class from Here.

Setup MySQL

Download and Install the MySQL Workbench from Here.

Download and Install the MySQL Client from Here.

Setup MuleSoft Project

Watch the below video for MuleSoft Setup and explanation

Resources

  1. MuleSoft Blog
  2. JWT Authentication Salesforce
  3. Platform Event with MuleSoft
  4. Platform Event in Salesforce

LEAVE A REPLY

Please enter your comment!
Please enter your name here