Capturing Real-time Record Updation Using LWC

Published on
May 14, 2025
Author
Salesforce Dev Team
Capturing Real-time Record Updation Using LWC

Introduction In modern CRM ecosystems, real-time Salesforce integration and seamless user experiences are no longer optional but fundamental for driving operational efficiency. Imagine your sales reps making important Opportunity changes, but the ERP remains out of sync, leading to confusion and data errors. We understood the necessity to bridge this data gap and implemented a… Continue reading Capturing Real-time Record Updation Using LWC

Introduction

In modern CRM ecosystems, real-time Salesforce integration and seamless user experiences are no longer optional but fundamental for driving operational efficiency. Imagine your sales reps making important Opportunity changes, but the ERP remains out of sync, leading to confusion and data errors. We understood the necessity to bridge this data gap and implemented a quick action-driven integration between Salesforce and an external ERP system via MuleSoft (Microsoft Business Central). Continue reading to know how we leveraged Platform Events, Lightning Web Components (LWC), and a lightweight Salesforce polling mechanism to ensure sales representatives stay informed directly on the record page – eliminating the need for manual refreshes.

The Business Challenge: Keeping Sales Data in Sync

The sales representatives frequently make changes to Opportunity records in Salesforce, which need to be promptly reflected in the external ERP system, Microsoft Business Central. This made our objectives clear:

  • Allow users to initiate sync manually via a Quick Action.
  • Notify the ERP system (via MuleSoft) of the Opportunity sync request using Platform Events in Salesforce.
  • Provide transparency by updating a Salesforce Sync Status Updates field based on the external system’s response.
  • Offer Rich text Component displaying sync feedback.
  • Ensure the sales representative remains on the same page without any reloads or redirection.

Our Technical Solution: Real-Time Updates with LWC and Smart Polling

To meet these needs, we built a Lightning Web Component (SyncOpportunityToBC) that performs the following steps:

  • Quick Action Initiation: A user-initiated Quick Action in Salesforce invokes the LWC, which then sends a Platform Event in Salesforce. This signals MuleSoft that a specific Opportunity record needs to be synchronised with Microsoft Business Central. This Quick Action has a conditional visibility which is controller by the Sync_Status__c. The button is only visible for values such as Not Synced, Out of Sync and Failed and gets hidden if the Sync is In Progress.
  • Real-Time Status Polling: Once the sync request is initiated, the LWC starts a Salesforce polling mechanism on a custom field (Sync_Status__c). This polling periodically checks for status updates from the external system, which can be “In Progress”, “Completed”, or “Failed”.
  • Visual Feedback via Rich Text Component: Based on the response from MuleSoft, the LWC dynamically updates a rich text component on the Opportunity record page, providing immediate feedback to the user about the real-time data sync in the Salesforce process.
  • Seamless UI Refresh Without Page Reloads in Salesforce: Using notifyRecordUpdateAvailable() and @wire(getRecord), within the LWC, we ensure that the data displayed on the record is refreshed in place, giving a real-time user experience.

Polling Mechanism: Real-Time Without Streaming

While Salesforce offers options like Change Data Capture and Streaming API for instant Salesforce integration, these can often involve setup overhead or licensing constraints. For this specific, user-initiated sync flow, we chose a controlled polling strategy. This approach is simple to implement and highly effective for short-term, user-initiated sync flows.

How Polling Works

As soon as the Opportunity sync with ERP Systems request is sent via the Platform Event in Salesforce, the LWC starts polling the backend every 2 seconds (customizable via pollingInterval). It uses an Apex method (getOpportunitySyncStatus) to efficiently retrieve the current value of the Sync_Status__c field.

Here’s a simplified version of the polling logic:

Reasons Why This Works Well

  • Lightweight Implementation: The process utilizes a straightforward Apex call, minimizing overhead.
  • Near Real-time Updates: It achieves timely updates within a 6-minute max window (customizable via maxRetries).
  • Cost-Effective: By this method, there’s no need for expensive external messaging or push-based architecture.
  • Controlled and Robust: The polling process cleanly terminates on success or timeout.

Achieving Real-Time UI Refresh with notifyRecordUpdateAvailable()

Once a terminal sync status is reached (“Completed” or “Failed”), we use:

await notifyRecordUpdateAvailable([{ recordId: this.recordId }]);

This line of code notifies Salesforce’s Lightning Data Service (LDS) that the specific Opportunity record has been updated. As a result, all components wired to that record (e.g., using @wire(getRecord)) automatically re-fetch the latest data.

In our case, the rich text field that displays sync status is directly bound to the Sync_Status__c field. This ensures a seamless update in the user interface, without a page refresh.

  • No manual intervention required
  • No disruptive page reloads
  • Just real-time updates

The Outcome: Tangible Benefits for Sales Teams

By implementing this real-time Salesforce integration solution, significant benefits were delivered:

  • Seamless User Experience: Reps stay on the record page throughout the sync.
  • Real-Time Visibility: Sync progress and results are shown almost instantly.
  • Enhanced Productivity: No manual refreshing allows reps to focus on other important tasks.
  • Decoupled and Efficient Integration: The combination of Platform Events in Salesforce and our controlled Salesforce polling mechanism enables clean, asynchronous operations between Salesforce and MuleSoft.

Conclusion

The implementation of a near real-time integration between Salesforce and an external ERP system underscores the essential role of efficient data synchronization in modern CRM ecosystems. By strategically leveraging Lightning Web Components, Platform Events, and a controlled polling mechanism, organizations can achieve significant improvements in operational efficiency, data accuracy, and user experience.

To explore the potential of implementing similar real-time integration solutions tailored to your organization’s specific requirements and technology landscape, connect with our experts today!

Recent Blogs

Connecting MuleSoft and Azure SQL with Entra ID
BlogJul 14, 2025

Connecting MuleSoft and Azure SQL with Entra ID

Introduction Establishing a secure connection between MuleSoft and Azure SQL Database can be challenging, especially if you are using Entra ID (formerly known as Azure Active Directory) for authentication. This blog walks through a fully working configuration for connecting to Azure SQL using ActiveDirectoryServicePrincipal in Mule runtime 4.7.4 with Java 8 — addressing driver setup,… Continue reading Connecting MuleSoft and Azure SQL with Entra ID

Read More
Blog
2 min read

Connecting MuleSoft and Azure SQL with Entra ID

Introduction Establishing a secure connection between MuleSoft and Azure SQL Database can be challenging, especially if you are using Entra ID (formerly known as Azure Active Directory) for authentication. This blog walks through a fully working configuration for connecting to Azure SQL using ActiveDirectoryServicePrincipal in Mule runtime 4.7.4 with Java 8 — addressing driver setup,… Continue reading Connecting MuleSoft and Azure SQL with Entra ID

Read More
Understanding Salesforce Flow Approval Processes
BlogJun 30, 2025

Understanding Salesforce Flow Approval Processes

Introduction: Salesforce introduced Flow Approval Processes in the Spring '25 release. This is an evolved version of the classic approval process model, powered by Flow Orchestrator. The new approach brings unprecedented flexibility, enabling the creation of dynamic, multi-level, and logic-driven approval workflows that are entirely declarative. Continue reading the blog to get a deeper understanding… Continue reading Understanding Salesforce Flow Approval Processes

Read More
Blog
5 min read

Understanding Salesforce Flow Approval Processes

Introduction: Salesforce introduced Flow Approval Processes in the Spring '25 release. This is an evolved version of the classic approval process model, powered by Flow Orchestrator. The new approach brings unprecedented flexibility, enabling the creation of dynamic, multi-level, and logic-driven approval workflows that are entirely declarative. Continue reading the blog to get a deeper understanding… Continue reading Understanding Salesforce Flow Approval Processes

Read More
All About Schedulers: Mule 4
BlogMay 7, 2025

All About Schedulers: Mule 4

In the world of Mule 4, automating repetitive tasks and triggering flows at defined intervals is necessary for building efficient and robust integration solutions. This is where Mule 4 schedulers come into use. This blog post explores the intricacies of scheduling in Mule 4, providing practical examples and best practices to help you get deeper… Continue reading All About Schedulers: Mule 4

Read More
Blog
7 min read

All About Schedulers: Mule 4

In the world of Mule 4, automating repetitive tasks and triggering flows at defined intervals is necessary for building efficient and robust integration solutions. This is where Mule 4 schedulers come into use. This blog post explores the intricacies of scheduling in Mule 4, providing practical examples and best practices to help you get deeper… Continue reading All About Schedulers: Mule 4

Read More
Demystifying CloudHub 2.0 Networking
BlogApr 30, 2025

Demystifying CloudHub 2.0 Networking

CloudHub 2.0 is the latest version of MuleSoft's powerful managed runtime platform, designed for seamless deployment of APIs and integrations. Unlike the original CloudHub 1.0, which relied on shared runtime workers within a single AWS region, CloudHub 2.0 offered a better upgrade. It provides a dedicated, isolated infrastructure with more granular control over networking, security,… Continue reading Demystifying CloudHub 2.0 Networking

Read More
Blog
7 min read

Demystifying CloudHub 2.0 Networking

CloudHub 2.0 is the latest version of MuleSoft's powerful managed runtime platform, designed for seamless deployment of APIs and integrations. Unlike the original CloudHub 1.0, which relied on shared runtime workers within a single AWS region, CloudHub 2.0 offered a better upgrade. It provides a dedicated, isolated infrastructure with more granular control over networking, security,… Continue reading Demystifying CloudHub 2.0 Networking

Read More