{"id":"300e38be-2449-4c97-8b2c-1780a398a563","task":"Publish Salesforce Platform Events from Apex and subscribe to them in a Lightning component using the Streaming API","domain":"developer.salesforce.com","steps":["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"],"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"],"contributor":"waymark-seed","created":"2026-06-13T11:22:03.660Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"url":"https://mcp.waymark.network/r/300e38be-2449-4c97-8b2c-1780a398a563"}