# Platform event publishing, subscribers and Pub/Sub API

*Platform Developer II Study Guide · Process Automation, Logic, and Integration · Last updated October 19, 2026 · https://www.certifyforce.com/study-guide/platform-developer-ii/process-automation-logic-and-integration/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.

- Certification: Salesforce Platform Developer II
- Exam section: Process Automation, Logic, and Integration
- Study guide: https://www.certifyforce.com/study-guide/platform-developer-ii

**Official exam objective:**

> Given a scenario, identify the appropriate publish / subscribe logic for platform events.

## What the exam expects

- Choose Publish Immediately or Publish After Commit from whether subscribers need committed data.
- Read `EventBus.publish` results correctly and get the final outcome with a publish callback.
- Write and configure a platform event Apex trigger: batch size, running user, `EventBus.RetryableException` and `setResumeCheckpoint`.
- Pick the subscriber: Apex trigger in the org, `lightning/empApi` in 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

| Fact | Detail | Source |
|---|---|---|
| Default publish behavior | Publish Immediately, even if the transaction fails | [Platform Event Fields](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-define-ui.html) |
| Publish After Commit | Not published if the transaction fails; counts as a DML statement | [Publish Event Messages with Apex](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-publish-apex.html) |
| isSuccess() true | Request queued; `OPERATION_ENQUEUED`; publish is asynchronous | [Publish Event Messages with Apex](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-publish-apex.html) |
| Final publish result | Apex publish callback passed to `EventBus.publish` | [Apex Publish Callbacks](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-publish-callbacks.html) |
| Trigger batch | Up to 2,000 messages; synchronous limits | [Subscribe to Platform Event Notifications with Apex Triggers](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-subscribe-apex.html) |
| Trigger running user | Automated Process unless PlatformEventSubscriberConfig sets one | [Configure the Platform Event Trigger](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-trigger-config.html) |
| Retries | Initial run plus 9; then the error state | [Retry Event Triggers with EventBus.RetryableException](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-subscribe-apex-refire.html) |
| SOQL on events | Not supported | [Considerations for Defining and Publishing Platform Events](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-considerations.html) |
| Retention | High-volume events kept 72 hours | [Enterprise Messaging Platform Events](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-intro-emp.html) |
| Unique message ID | EventUuid, not ReplayId | [Platform Event Fields](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-define-ui.html) |
| Test delivery | After `Test.stopTest()` or `Test.getEventBus().deliver()` | [Testing Your Platform Event in Apex](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-event-apex-tests.html) |

## Check yourself

- 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`?

## Sources

- [Publish Event Messages with Apex](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-publish-apex.html)
- [Platform Event Fields](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-define-ui.html)
- [Subscribe to Platform Event Notifications with Apex Triggers](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-subscribe-apex.html)
- [Comparing setResumeCheckpoint() and EventBus.RetryableException](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-subscribe-compare-checkpoint-retryable.html)
- [Retry Event Triggers with EventBus.RetryableException](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-subscribe-apex-refire.html)
- [Configure the User and Batch Size for Your Platform Event Trigger](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-trigger-config.html)
- [Apex Trigger Best Practices (Platform Events)](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-trigger-reco.html)
- [Apex Publish Callbacks](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-publish-callbacks.html)
- [Get Started with Pub/Sub API](https://developer.salesforce.com/docs/platform/pub-sub-api/guide/intro.html)
- [Subscribe to Platform Event Notifications with Pub/Sub API](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-subscribe-pubsub-api.html)
- [Subscribe to Platform Event Notifications in a Lightning Component](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-subscribe-lc.html)
- [Enterprise Messaging Platform Events](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-intro-emp.html)
- [Considerations for Defining and Publishing Platform Events](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-events-considerations.html)
- [Testing Your Platform Event in Apex](https://developer.salesforce.com/docs/platform/platform-events/guide/platform-event-apex-tests.html)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit and reading progress are included in the full study guide. The separate practice exams option includes the reviewed question bank and timed mock exams. The bundle includes both where available. See [current options and prices](https://www.certifyforce.com/pricing).
