Choose the Publishing Behavior for Your Platform Event

When you define or modify a platform event, you can choose when the platform event message is published in a Lightning Platform transaction. Choose to have the event message published only after a transaction is committed or immediately when the publish call executes. Previously, platform event messages were published immediately.

Where: This change applies to Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.

Why: Choose to publish after a transaction is committed if subscribers rely on data that the publishing transaction commits. For example, a process publishes an event message and creates a task record. A second process that is subscribed to the event is fired and expects to find the task record. For this scenario, choose the post-commit publishing behavior for the platform event. Another reason for choosing this behavior is when you don’t want the event message to be published if the transaction fails.

Choose to publish immediately if you want the event message to be available regardless of whether the transaction succeeds. Also choose this publishing behavior if the publisher and subscribers are independent and subscribers don’t rely on data committed by the publisher. For example, the immediate publishing behavior is suitable for an event used for logging purposes.

How: You can define the publishing behavior in Setup or through Metadata API. In Setup, enter Platform Events in the Quick Find box, then select Platform Events. Add a platform event or edit an existing one.

Select the publish behavior on the platform event page in Setup

In Metadata API, set the new publishBehavior field on the CustomObject type to a valid value.

For platform events created before Summer ’19, the publish behavior remains publish immediately.



The publish behavior option applies to event messages published through the Lightning Platform, such as Apex, Process Builder, and Flow Builder, and through Salesforce APIs.