Skip to content
Namaste Salesforce Namaste Salesforce
Developer Roadmap

Platform Events

Decouple systems with Platform Events — Salesforce’s publish/subscribe event bus for real-time messaging.

Developer Roadmap Article 1 min

Platform Events

Not every integration should be a direct, synchronous call. When systems need to stay loosely coupled — a publisher should not know or wait for its subscribers — Salesforce offers Platform Events, a publish/subscribe event bus built into the platform. Publishers fire events; any number of subscribers react, now or slightly later, without the publisher being aware of them.

A platform event is defined like an sObject (its API name ends in __e) with custom fields that form the event's payload. You publish an event by inserting an instance of it via DML or the EventBus.publish() method, and you subscribe from Apex triggers, Flows, Lightning components (via empApi), or external systems using the CometD-based streaming API.

// Publish a platform event
Order_Placed__e evt = new Order_Placed__e(
    Order_Number__c = 'SO-1001',
    Amount__c       = 4999.00
);
Database.SaveResult sr = EventBus.publish(evt);
if (!sr.isSuccess()) {
    // handle publish failure
}
// Subscribe with an "after insert" trigger on the event
trigger OrderPlacedTrigger on Order_Placed__e (after insert) {
    for (Order_Placed__e e : Trigger.new) {
        // react: create a Task, call another system, etc. — bulk-safe
    }
}

The value is decoupling. An order-management system can publish an "Order Placed" event and walk away; a fulfilment subscriber, an analytics subscriber, and a notification subscriber each react independently. Adding a new subscriber later requires no change to the publisher. Because delivery is asynchronous and retried, it also smooths spikes and survives transient failures better than a chain of synchronous callouts.

Know the trade-offs: events are fire-and-forget, so there is no synchronous return value, and ordering and delivery guarantees differ from a database transaction. Use platform events for notifications and eventual-consistency workflows, not when you need an immediate answer.

As an exercise, define an Order_Placed__e event, publish it from anonymous Apex, and write a trigger that logs each received event. Event-driven design scales beautifully; the roadmap's final lesson covers the DevOps practices that let you ship all of this safely.

Advertise with us · 728×90