# Platform event publishing, subscribers and Pub/Sub API

*Platform Developer II Study Guide · Process Automation, Logic, and Integration · Last updated October 16, 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/atlas.en-us.platform_events.meta/platform_events/platform_events_define_ui.htm) |
| Publish After Commit | Not published if the transaction fails; counts as a DML statement | [Publish Event Messages with Apex](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_apex.htm) |
| isSuccess() true | Request queued; `OPERATION_ENQUEUED`; publish is asynchronous | [Publish Event Messages with Apex](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_apex.htm) |
| Final publish result | Apex publish callback passed to `EventBus.publish` | [Apex Publish Callbacks](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_callbacks.htm) |
| Trigger batch | Up to 2,000 messages; synchronous limits | [Subscribe to Platform Event Notifications with Apex Triggers](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_apex.htm) |
| Trigger running user | Automated Process unless PlatformEventSubscriberConfig sets one | [Configure the Platform Event Trigger](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_trigger_config.htm) |
| Retries | Initial run plus 9; then the error state | [Retry Event Triggers with EventBus.RetryableException](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_apex_refire.htm) |
| SOQL on events | Not supported | [Considerations for Defining and Publishing Platform Events](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_considerations.htm) |
| Retention | High-volume events kept 72 hours | [Enterprise Messaging Platform Events](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_intro_emp.htm) |
| Unique message ID | EventUuid, not ReplayId | [Platform Event Fields](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_define_ui.htm) |
| Test delivery | After `Test.stopTest()` or `Test.getEventBus().deliver()` | [Testing Your Platform Event in Apex](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_event_apex_tests.htm) |

## 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/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_apex.htm)
- [Platform Event Fields](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_define_ui.htm)
- [Subscribe to Platform Event Notifications with Apex Triggers](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_apex.htm)
- [Comparing setResumeCheckpoint() and EventBus.RetryableException](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_compare_checkpoint_retryable.htm)
- [Retry Event Triggers with EventBus.RetryableException](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_apex_refire.htm)
- [Configure the User and Batch Size for Your Platform Event Trigger](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_trigger_config.htm)
- [Apex Trigger Best Practices (Platform Events)](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_trigger_reco.htm)
- [Get the Result of Asynchronous Platform Event Publishing with Apex Publish Callbacks](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_publish_callbacks.htm)
- [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/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_pubsub_api.htm)
- [Subscribe to Platform Event Notifications in a Lightning Component](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_lc.htm)
- [Enterprise Messaging Platform Events](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_intro_emp.htm)
- [Considerations for Defining and Publishing Platform Events](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_considerations.htm)
- [Testing Your Platform Event in Apex](https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_event_apex_tests.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 9 linked practice questions, and unlimited timed mock exams are included with the Platform Developer II pack (USD $19): https://www.certifyforce.com/practice-exams
