Define a Platform Event object in Setup with the suffix __e (e.g., Order_Update__e) and add custom fields to carry event payload data
In Apex, create an instance of the Platform Event sObject, populate its fields, and publish using EventBus.publish(event); check the SaveResult for errors
To subscribe in a Lightning Web Component, import the platform event channel using the @wire adapter or the Lightning Message Service; alternatively use the emp-api module with subscribe(channel, replayId, callback)
In a Flow, use the Publish Platform Event core action to fire events without Apex, selecting the event type and mapping field values from flow variables
On external systems, subscribe via CometD using the /event/EventName__e channel, authenticating with a Salesforce session token and specifying a replayId of -1 for new events or -2 for all retained events
Monitor event publishing via the Platform Events Usage metrics in Setup and check EventBusSubscriber records to verify subscriber registration
Known gotchas
Platform Events are published asynchronously — EventBus.publish() in a before trigger fires only after the triggering transaction commits; if the transaction rolls back, the event is not published
The default event retention window is 24 hours; subscribers that go offline for longer than the retention window will miss events and must handle the gap using a replay ID of -2 with caution
Each platform event publish counts against the daily Platform Event publish allocation; high-volume triggers that fire on every record save can exhaust org-level limits quickly
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp