Skip to main content

Platform Event subscriptions in LWC

About Us
Published by JET BI
03 December 2024
103

Platform Event subscriptions in LWC for live-data sync

INTRODUCTION

WHAT ARE PLATFORM EVENTS?

Platform Events are a part of Salesforce's event-driven architecture. They allow different systems to communicate with each other in real-time. You can think of them as messages that can be sent and received between Salesforce and external applications.


WHY USE PLATFORM EVENTS?

Using Platform Events has many benefits:

  • Real-Time Communication: They allow you to receive updates instantly.
  • Decoupled Architecture: Different systems can work independently.
  • Scalability: They can handle large volumes of events.

 

PROJECT SCENARIO

Imagine you are building a customer support application. When a support ticket is updated, you want all users to see the changes immediately. This is where Platform Events come in.

Step 1: Create a Platform Event

  • Go to Setup in Salesforce.
  • Search for Platform Events.
  • Click on New Platform Event.
  • Define the fields you need, such as Ticket ID, Status, and Updated By.

Step 2: Publish Events

In your backend (Apex), you will publish an event whenever a ticket is updated. Here’s a simple example:


 

Step 3: Subscribe to Events in LWC

Now, let's see how to subscribe to these events in LWC using the EMP API.

  • Install the empApi: Make sure you have the empApi library available in your LWC project.
  • Create a Lightning Web Component:

Step 4: Display Updates

Finally, you can display the updates in your component's HTML file:

 

CONCLUSION

Using Platform Events in LWC allows you to synchronize data in real-time effectively. In our example, we demonstrated how to create a Platform Event, publish it from Apex, and subscribe to it in an LWC component. This approach can significantly improve the user experience by providing instant updates.


Yuriy Rudenko
Salesforce developer
image
Expertise
Question to the expert
image

We have available resources to start working on your project within 5 business days

1 UX Designer

image

1 Admin

image

2 QA engineers

image

1 Consultant

image
Related Articles
All articles
image
How to Customize Salesforce Field Service Mobile for Your Technicians
Salesforce Field Service Mobile provides a standard technician experience that companies can extend to fit their own service processes. This article looks at areas where a custom mobile workflow can help: AI repair assistance, field documentation, external tools, back-office integrations, quotes and payments on site, barcode scanning and role-based mobile layouts. It also outlines four practical steps for planning a mobile workflow around the technician’s work.
21 October 2026
image
Salesforce Field Service Mobile: New Capabilities for Technicians
Salesforce Field Service Mobile continues to evolve with new capabilities for technicians working in the field. Explore how updates to job preparation, mobile forms, voice input, mapping, and Work Order views are changing the technician experience, and learn why configuring these capabilities around your service operations matters.
14 October 2026
image
Closing the Gap Between Field Service and Business Needs
Standard Salesforce Field Service configuration covers many service processes, but individual businesses can have different workflows, working conditions, scheduling rules, and operational requirements. This article looks at three areas where standard configuration can fall short: how technicians work, the conditions of field service operations, and business-specific processes. It also provides a practical checklist of signs that a Salesforce Field Service setup could benefit from customization.
07 October 2026