Platform event publishing, subscribers and Pub/Sub API
Publish Immediately versus Publish After Commit, what EventBus.publish's SaveResult really means, how platform event Apex triggers run, retry and resume, and which subscriber to use: an Apex trigger, empApi in a Lightning component, or Pub/Sub API with replay IDs and EventUuid deduplication.
Given a scenario, identify the appropriate publish / subscribe logic for platform events.
~7 min read · 9 practice questions ·
What the exam expects
- Choose Publish Immediately or Publish After Commit from whether subscribers need committed data.
- Read
EventBus.publishresults correctly and get the final outcome with a publish callback. - Write and configure a platform event Apex trigger: batch size, running user,
EventBus.RetryableExceptionandsetResumeCheckpoint. - Pick the subscriber: Apex trigger in the org,
lightning/empApiin a component, Pub/Sub API for an external client. - Design a resilient external subscriber with replay IDs and deduplicate on
EventUuid.
Key terms: publish behavior (Publish Immediately or Publish After Commit, set on the event definition), replay ID (the opaque position of a message in the event stream), EventUuid (the always-unique identifier of an event message), Pub/Sub API (gRPC-based API that publishes, subscribes and returns event schemas), PlatformEventSubscriberConfig (metadata that sets a trigger's running user and batch size).
Key facts
- Detail
- Publish Immediately, even if the transaction fails
- Detail
- Not published if the transaction fails; counts as a DML statement
- Detail
- Request queued;
OPERATION_ENQUEUED; publish is asynchronous
- Detail
- Apex publish callback passed to
EventBus.publish
- Detail
- Up to 2,000 messages; synchronous limits
- Detail
- Automated Process unless PlatformEventSubscriberConfig sets one
- Detail
- Initial run plus 9; then the error state
- Detail
- Not supported
- Detail
- High-volume events kept 72 hours
- Detail
- EventUuid, not ReplayId
- Detail
- After
Test.stopTest()orTest.getEventBus().deliver()
Sources for this section (9)
- Platform Event Fieldsdeveloper.salesforce.com (opens in a new tab)
- Publish Event Messages with Apexdeveloper.salesforce.com (opens in a new tab)
- Apex Publish Callbacksdeveloper.salesforce.com (opens in a new tab)
- Subscribe to Platform Event Notifications with Apex Triggersdeveloper.salesforce.com (opens in a new tab)
- Configure the Platform Event Triggerdeveloper.salesforce.com (opens in a new tab)
- Retry Event Triggers with EventBus.RetryableExceptiondeveloper.salesforce.com (opens in a new tab)
- Considerations for Defining and Publishing Platform Eventsdeveloper.salesforce.com (opens in a new tab)
- Enterprise Messaging Platform Eventsdeveloper.salesforce.com (opens in a new tab)
- Testing Your Platform Event in Apexdeveloper.salesforce.com (opens in a new tab)
- When should an event use Publish After Commit?
- Why can't a platform event trigger send email by default?
- Why deduplicate on EventUuid instead of ReplayId?
- What happens to DML already performed when a trigger throws `EventBus.RetryableException`?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Platform Developer II pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 28 lessons of the Platform Developer II guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (9 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams