My scenario is the following:
- an Opportunity is updated
- for some updates, the Opportunity before update trigger needs to update one or more OpportunityLineItems. The before update trigger cannot do the updates directly (exceptions are thrown); the trigger therefore publishes a Platform Event
UpdateLinitems__ewith publish behaviour
Publish After Commit.
UpdateLineItems__eafter insert trigger updates the line items based on the information in the event.
- next, the
UpdateLineItems__eafter insert trigger publishes a Platform Event
UIRefresh__ewhich will be handled by a VF page. The VF page rerenders the entire page or parts thereof.
The Question is: what is the correct publish behavior setting for the
I guess the answer depends on whether or not we are in a transaction while the
UpdateLineItems__e trigger is executing and / or on what happens when an event is published with behavior
Publish After Commit when there is no current transaction.
- when the
UpdateLinitems__etrigger is executing within a transaction, the event must certainly be published after commit, otherwise the event might be consumed before the commit.
- when the
UpdateLinitems__etrigger is not executing within a transaction I need to know what happens when I publish
Publish After Commitoutside of a transaction context. For instance, when not in a transaction, is
Publish After Committhe same as
Publish Immediately? That is, when in doubt, I can always use
Publish After Commit?