[SalesForce] Platform Events- Length of time an event is published for

When you publish a Platform Event, how long does it stay published for?

I know the subscribers can enter into a state of idle or expire if they are not sure for a certain length of time. Is there anything like that for when you publish the platform event?

UPDATE:
https://trailhead.salesforce.com/en/modules/platform_events_basics/units/platform_events_define_publish

It says here that it will store the PE for 24 hours. Is that considered being "published" for 24 hours, or it is storing the data for 24 hours?

Best Answer

Platform events are inherently momentary. They don't have a duration as such, but they are stored on the platform for 24 hours to facilitate replay.

Events exist in a channel, a stream, which is watched by one or more subscribers. They aren't independent objects, they don't store state, and they have no permanence - they simply represent some occurrence that is to be observed. If an event exists, it has been published; there's no transition into or out of a published state.

The CometD-based Streaming API, on which Platform Events are built, supports a replay mechanism, whereby subscribers can jump backwards in the stream of messages to a fixed point (the Replay ID of the last message they received) and have messages between that point and the present re-sent to the subscriber. That doesn't imply that the events are in a "published" state for 24 hours (because, as above, events don't have that kind of state), but that they can be accessed by a client through replay during that time window. For example, if a client drops connection for an hour, it can replay all of the events since the last event it received by supplying that event's replay ID. If its connection drops for more than 24 hours, it's out of luck.

Replay is available only through API subscriptions, not Apex.