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.
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.