An enterprise Salesforce org utilizes Platform Events to decouple order processing services. A developer needs to ensure that when a custom Platform Event is published, subscriber processing failures do not cause the publishing transaction to roll back, and subscribers can resume processing from the exact point of failure after a system outage. Which configuration and implementation approach should the developer choose?
Trap 1: Publish the event using Database.insert(event, true) within a…
Using allOrNone as true and executing synchronous subscriber logic inside triggers couples the publisher and subscriber tightly. This defeats the asynchronous decoupling benefit of Platform Events and risks transaction failures across the entire publishing chain.
Trap 2: Implement a custom REST service where subscribers poll Salesforce…
Polling via custom REST services introduces high API consumption, unnecessary database queries, and significant latency compared to push-based Platform Events. Salesforce Platform Events provide native streaming infrastructure designed specifically to avoid polling.
Trap 3: Publish the event with immediate publishing behavior so subscribers…
Immediate publishing causes subscriber errors to roll back the publisher's transaction, violating the primary architectural goal of decoupling. Furthermore, immediate publishing does not support subscriber retry mechanisms or durable event retention.
- A
Publish the event using Database.insert(event, true) within a trigger that synchronously calls subscriber Apex classes in a chained loop.
Why it fails: Using allOrNone as true and executing synchronous subscriber logic inside triggers couples the publisher and subscriber tightly. This defeats the asynchronous decoupling benefit of Platform Events and risks transaction failures across the entire publishing chain.
- B
Configure the Platform Event publishing behavior to publish after successfully committing the database transaction, and use an Apex trigger with asynchronous processing for subscribers.
Publishing after commit ensures events are only emitted when the underlying database transaction succeeds, preventing ghost events. Subscribers running asynchronously via Apex triggers process events independently without impacting the original publisher's transaction state.
- C
Implement a custom REST service where subscribers poll Salesforce every 5 seconds, storing the last processed timestamp in a custom object.
Why it fails: Polling via custom REST services introduces high API consumption, unnecessary database queries, and significant latency compared to push-based Platform Events. Salesforce Platform Events provide native streaming infrastructure designed specifically to avoid polling.
- D
Publish the event with immediate publishing behavior so subscribers execute within the exact same database transaction as the publisher.
Why it fails: Immediate publishing causes subscriber errors to roll back the publisher's transaction, violating the primary architectural goal of decoupling. Furthermore, immediate publishing does not support subscriber retry mechanisms or durable event retention.