In today’s API-driven landscape, real-time integration is key. Salesforce Platform Events provide a powerful event-driven architecture that helps developers build scalable, loosely-coupled integrations across systems.
In this comprehensive guide, you’ll learn how to use Platform Events to build responsive, scalable, and maintainable integrations inside and outside of Salesforce.
Platform Events are part of Salesforce’s Event-Driven Architecture (EDA), allowing systems to communicate through publish-subscribe models. Instead of querying for changes or writing synchronous APIs, you publish and subscribe to events asynchronously.
Feature | Platform Events | REST API | Outbound Messaging |
---|---|---|---|
Real-time | ✅ | ✅ | ✅ |
Asynchronous | ✅ | ❌ | ✅ |
Retry logic | ✅ | ❌ | ❌ |
Order of execution | ✅ | ❌ | ❌ |
Declarative support | ✅ | ❌ | ✅ |
Order_Event__e
)OrderId__c
, Status__c
, or CustomerEmail__c
Platform Events use the __e
suffix and behave like sObjects.
Publishing a Platform Event is as simple as inserting a record:
Order_Event__e event = new Order_Event__e(OrderId__c = '12345',Status__c = 'Shipped',CustomerEmail__c = 'user@example.com');Database.SaveResult sr = EventBus.publish(event);
You can publish from Apex triggers, classes, or even Flow Builder.
trigger OrderEventTrigger on Order_Event__e (after insert) {for (Order_Event__e evt : Trigger.new) {System.debug('Received Order ID: ' + evt.OrderId__c);// Execute business logic}}
You can create declarative subscribers in Flow Builder that listen to Platform Events and execute logic like record creation or email alerts.
External systems (e.g., AWS Lambda, Node.js apps) can subscribe via CometD using Salesforce’s Streaming API.
This architecture is fully asynchronous, event-driven, and scalable.
Use replay IDs for durable subscriptions and guaranteed delivery in case of disconnections.
Platform Events are subject to limits (e.g., 150K events/day for Enterprise Edition). Monitor usage via Event Monitoring.
Use Apex triggers with future or queueable classes for processing to avoid long-running operations.
Use EventBus.publish()
to publish events instead of DML for enhanced control and error handling.
Test.startTest()
and Test.stopTest()
Use Test.getEventBus().deliver()
in unit tests for reliable testing of event-based logic.
Feature | Platform Events | Change Data Capture |
---|---|---|
Custom fields | ✅ | ❌ |
Data change tracking | ❌ | ✅ |
External consumption | ✅ | ✅ |
Triggers support | ✅ | ✅ |
Built-in object support | ❌ | ✅ (standard & custom objects) |
Use CDC for tracking changes and Platform Events for broadcasting messages across apps.
Shipping_Event__e
, Inventory_Event__e
)Platform Events are a cornerstone for modern, scalable Salesforce integrations. They provide the speed, flexibility, and decoupling needed to build reliable cross-system architectures.
Start using Platform Events today to unlock true real-time automation in Salesforce.
Need help architecting your integration? Drop your scenario in the comments, and let’s discuss the best event-driven design!
Quick Links
Legal Stuff