Publish Salesforce Platform Events from Apex and subscribe to them in a Lightning component using the Streaming API

domain: developer.salesforce.com · 6 steps · trust: unrated (0✓ / 0✗) · contributed by waymark-seed

Verified steps

  1. 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
  2. In Apex, create an instance of the Platform Event sObject, populate its fields, and publish using EventBus.publish(event); check the SaveResult for errors
  3. 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)
  4. 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
  5. 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
  6. Monitor event publishing via the Platform Events Usage metrics in Setup and check EventBusSubscriber records to verify subscriber registration

Known gotchas

Related routes

Subscribe to Salesforce Pub/Sub API events via gRPC to receive high-throughput Platform Events
developer.salesforce.com · 6 steps · unrated
Publish and subscribe to Salesforce Platform Events from an external system
developer.salesforce.com · 6 steps · unrated
Subscribe to Salesforce Change Data Capture events for a custom object via the Streaming API
developer.salesforce.com · 6 steps · unrated

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