{"id":1628,"date":"2026-09-10T17:00:00","date_gmt":"2026-09-10T11:30:00","guid":{"rendered":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/"},"modified":"2026-09-10T17:00:00","modified_gmt":"2026-09-10T11:30:00","slug":"salesforce-platform-events-apex","status":"publish","type":"post","link":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/","title":{"rendered":"Salesforce Platform Events in Apex: Publish and Subscribe"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Salesforce Platform Events let different parts of a system talk by sending messages instead of calling each other directly. One part publishes an event, such as &#8220;payment received&#8221;, and any number of subscribers react to it: an Apex trigger, a flow, a Lightning component or an outside system. The publisher does not need to know who is listening.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this post, you will learn how to define an event, publish it from Apex, subscribe with an Apex trigger, and handle retries and replay. It builds on <a href=\"https:\/\/swapnilzambare.com\/blog\/asynchronous-apex-overview\/\">Asynchronous Apex<\/a>, <a href=\"https:\/\/swapnilzambare.com\/blog\/apex-trigger-basics-context-variables\/\">Apex trigger basics<\/a> and <a href=\"https:\/\/swapnilzambare.com\/blog\/scheduled-apex-cron-expressions\/\">Scheduled Apex<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Salesforce Platform Events?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce Platform Events are custom messages that you define like a custom object, with an API name ending in __e. Each event has fields that carry data, such as Enrolment_Id__c and Amount__c. Events go onto the event bus, a stream that keeps them for a short time so subscribers can read them in order.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of a radio station. The station broadcasts a message once, and every radio tuned to that channel hears it. The station does not call each listener, and new radios can tune in at any time. In this picture, the event bus is the radio channel, and subscribers are the radios.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Salesforce Platform Events Matter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Direct calls between systems make them depend on each other. Here is why Salesforce Platform Events matter at Bright Path Tutors.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, the payment partner sends a &#8220;payment received&#8221; event, and Salesforce updates the enrolment.<\/li>\n\n<li>Also, when a course is cancelled, several systems must react, such as email, accounting and the website.<\/li>\n\n<li>Next, the publisher stays simple, because it only sends one event.<\/li>\n\n<li>New subscribers can join later without changing the publisher.<\/li>\n\n<li>Finally, events can carry data out of Salesforce in near real time.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">So Salesforce Platform Events keep systems loosely coupled and easy to extend.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How Salesforce Platform Events Work<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce Platform Events follow a publish and subscribe flow. First, an admin or developer defines the event and its fields in Setup. Next, a publisher creates an event instance and calls EventBus.publish, or an outside system publishes through an API. Then the event goes onto the event bus, with a ReplayId that marks its position. After that, each subscriber receives the event, for example an Apex trigger on the event object. Finally, the subscriber processes it in its own transaction, separate from the publisher&#8217;s.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-1-1024x640.png\" alt=\"Salesforce Platform Events diagram showing define, publish, event bus, deliver, subscribe and process\" class=\"wp-image-1626\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-1-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-1-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-1-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-1-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">How events move from publisher to subscribers.<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Defining an Event<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create events in Setup &gt; Platform Events. Add fields like you would on a custom object. Events have no record pages and are not stored like normal records.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Publish Behaviour<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Each event has a publish behaviour. Publish After Commit sends the event only if the transaction succeeds. Publish Immediately sends it at once, even if the transaction later fails, which suits logging.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Publishing from Apex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Call EventBus.publish with one event or a list. It returns Database.SaveResult values that tell you whether publishing was accepted.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Subscribing with Apex Triggers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Event triggers support only after insert. They run in their own process, by default as the Automated Process user, and can receive up to 2,000 events per batch.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Subscribers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Flows can start from a platform event. Lightning components can subscribe with the empApi module. Outside systems use the Pub\/Sub API.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Retries and Replay<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Throw EventBus.RetryableException to ask Salesforce to send the batch again, up to 9 times. Each event has a ReplayId, so subscribers can resume from a position after a break.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Publish After Commit vs Publish Immediately<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below compares the two publish behaviours.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th>Publish After Commit<\/th><th>Publish Immediately<\/th><\/tr><\/thead><tbody><tr><td>Sent when<\/td><td>Transaction commits<\/td><td>At once<\/td><\/tr><tr><td>If the transaction fails<\/td><td>Event is not sent<\/td><td>Event is still sent<\/td><\/tr><tr><td>Typical use<\/td><td>Business events<\/td><td>Logs and monitoring<\/td><\/tr><tr><td>Matches saved data<\/td><td>Yes<\/td><td>Not always<\/td><\/tr><tr><td>Default for new events<\/td><td>Yes<\/td><td>No<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When to use which is simple. Use Publish After Commit for business events that depend on saved data. Use Publish Immediately for logs that must survive a rollback.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-2-1024x640.png\" alt=\"Salesforce Platform Events diagram comparing Publish After Commit and Publish Immediately\" class=\"wp-image-1627\" srcset=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-2-1024x640.png 1024w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-2-300x188.png 300w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-2-768x480.png 768w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-2-1536x960.png 1536w, https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Publish After Commit vs Publish Immediately.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Payment_Received__e Fields<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The table below lists the fields of our event.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Field<\/th><th>Type<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td>Enrolment_Id__c<\/td><td>Text(18)<\/td><td>a025g00000XyZ12AAB<\/td><\/tr><tr><td>Amount__c<\/td><td>Number(16, 2)<\/td><td>5000<\/td><\/tr><tr><td>Payment_Ref__c<\/td><td>Text(50)<\/td><td>PAY-2026-0911<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">A Real Salesforce Platform Events Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s use Salesforce Platform Events at Bright Path Tutors. The payment partner publishes Payment_Received__e, and Salesforce marks the enrolment as paid.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Publish from Apex<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Payment_Received__e evt = new Payment_Received__e(\n    Enrolment_Id__c = 'a025g00000XyZ12AAB',\n    Amount__c = 5000,\n    Payment_Ref__c = 'PAY-2026-0911');\n\nDatabase.SaveResult sr = EventBus.publish(evt);\nSystem.debug(sr.isSuccess() ? 'Event published' : 'Publish failed: ' + sr.getErrors());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In production, the partner publishes through an API. Here we publish Salesforce Platform Events from anonymous Apex to test. The SaveResult shows whether the event bus accepted it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Subscribe with a Trigger<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>trigger PaymentReceivedTrigger on Payment_Received__e (after insert) {\n\n    Map&lt;Id, Payment_Received__e&gt; byEnrolment = new Map&lt;Id, Payment_Received__e&gt;();\n    for (Payment_Received__e evt : Trigger.new) {\n        byEnrolment.put(Id.valueOf(evt.Enrolment_Id__c), evt);\n    }\n\n    List&lt;Enrolment__c&gt; updates = new List&lt;Enrolment__c&gt;();\n    for (Id enrolmentId : byEnrolment.keySet()) {\n        updates.add(new Enrolment__c(Id = enrolmentId, Is_Paid__c = true));\n    }\n    Database.update(updates, false, AccessLevel.SYSTEM_MODE);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The trigger collects the enrolment Ids from all events in the batch, then updates them in one DML statement. Because it runs as the Automated Process user, it uses system mode explicitly, and allOrNone false keeps one bad Id from failing the rest.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Check the Result<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is what the debug logs show for the publisher and the subscriber.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Publisher:  USER_DEBUG|Event published\nSubscriber: CODE_UNIT_STARTED|PaymentReceivedTrigger on Payment_Received__e\n            DML_BEGIN|Op:Update|Type:Enrolment__c|Rows:1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The publisher and subscriber run in separate transactions. So the trigger&#8217;s log has its own entry, and its success does not affect the publisher.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing Salesforce Platform Events<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Publish events between Test.startTest and Test.stopTest. The events are delivered at stopTest, so your asserts see the trigger&#8217;s results. You can also call Test.getEventBus().deliver() to deliver them earlier.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Salesforce Platform Events<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Expecting event triggers to support before insert or update events.<\/li>\n\n<li>Using Publish Immediately for business events that need saved data.<\/li>\n\n<li>Forgetting that event triggers run as the Automated Process user.<\/li>\n\n<li>Retrying forever with RetryableException instead of handling the error.<\/li>\n\n<li>Writing non-bulk trigger code for batches of up to 2,000 events.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for Salesforce Platform Events<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Name events after business facts, such as Payment_Received__e.<\/li>\n\n<li>Keep event payloads small and focused.<\/li>\n\n<li>Write bulk-safe triggers that handle many events at once.<\/li>\n\n<li>Check SaveResult after every publish.<\/li>\n\n<li>Monitor event usage against your org&#8217;s allocations.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a Course_Cancelled__e event with a Course_Id__c field. Publish it from the course trigger when Status changes to Cancelled, and subscribe with a flow that emails enrolled students. Hint: use Publish After Commit so emails go out only when the cancellation is saved.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Most Asked Interview Questions on Salesforce Platform Events<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Event-driven questions are common in integration interviews. Here are the 21 questions asked most about Salesforce Platform Events.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Questions on Salesforce Platform Events<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1: What are platform events?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Custom messages, ending in __e, that publishers send and subscribers receive through the event bus.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2: How do you publish an event in Apex?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Call EventBus.publish with an event instance or a list of events.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3: What does EventBus.publish return?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Database.SaveResult values that show whether publishing was accepted.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q4: Who can subscribe to platform events?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex triggers, flows, Lightning components with empApi, and outside systems through the Pub\/Sub API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q5: Which trigger event do platform event triggers support?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Only after insert.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q6: What is the event bus?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A stream that holds events in order so subscribers can receive them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q7: What is a ReplayId?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A value that marks an event&#8217;s position on the bus, used to resume subscriptions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Code and Scenario Questions on Salesforce Platform Events<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q8: What is the difference between the two publish behaviours?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Publish After Commit sends only if the transaction succeeds. Publish Immediately sends at once.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q9: Which user runs a platform event trigger by default?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Automated Process user.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q10: How many events can a trigger batch contain?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Up to 2,000.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q11: How do you retry an event trigger?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Throw EventBus.RetryableException. Salesforce retries up to 9 times.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q12: How do you test a platform event trigger?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Publish between startTest and stopTest, or call Test.getEventBus().deliver(), then assert.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q13: Can you roll back a published event?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not with Publish Immediately. With Publish After Commit, a failed transaction never sends it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q14: How do you process part of a batch and resume later?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use setResumeCheckpoint with the last processed ReplayId.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced Questions on Salesforce Platform Events<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q15: Why use platform events instead of direct callouts?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They decouple systems, so publishers and subscribers can change independently.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q16: Why should an event trigger use explicit access modes?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It runs as the Automated Process user, which may lack object and field permissions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q17: How long are events kept on the bus?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For a limited time, typically up to 72 hours, so subscribers can replay recent events.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q18: Can you change the running user of an event trigger?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, with a PlatformEventSubscriberConfig setting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q19: What are event allocations?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Limits on how many events an org can publish and deliver in a period.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q20: How do platform events differ from Change Data Capture?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Platform events carry custom messages you design. Change Data Capture sends events for record changes automatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q21: How do you avoid duplicate processing?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Make subscribers idempotent, for example by checking a unique Payment_Ref__c before updating.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/platform-events\/guide\/platform-events-intro.html\" target=\"_blank\" rel=\"noopener noreferrer\">Platform Events Developer Guide<\/a><\/li>\n\n<li><a href=\"https:\/\/developer.salesforce.com\/docs\/platform\/platform-events\/guide\/platform-events-subscribe-apex-refire.html\" target=\"_blank\" rel=\"noopener noreferrer\">Retry Event Triggers with EventBus.RetryableException<\/a><\/li>\n\n<li><a href=\"https:\/\/trailhead.salesforce.com\/content\/learn\/modules\/platform_events_basics\" target=\"_blank\" rel=\"noopener noreferrer\">Platform Events Basics (Trailhead)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Salesforce Platform Events are custom messages that end in __e.<\/li>\n\n<li>Publish with EventBus.publish and check the SaveResult.<\/li>\n\n<li>Event triggers support only after insert and run in their own process.<\/li>\n\n<li>Publish After Commit suits business events, Publish Immediately suits logs.<\/li>\n\n<li>Retries and ReplayIds help subscribers recover from errors.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce can also publish events for record changes automatically. Next, read our guide to <a href=\"https:\/\/swapnilzambare.com\/blog\/change-data-capture-salesforce-apex\/\">Change Data Capture in Salesforce<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Salesforce Platform Events let different parts of a system talk by sending messages instead of calling each other directly. One part publishes an event,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1625,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[8,96],"tags":[68,98,112,81,91,7,97],"swapz_series":[],"class_list":["post-1628","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce","category-salesforce-developer","tag-advanced","tag-apex","tag-async-apex","tag-integration","tag-interview-questions","tag-salesforce","tag-salesforce-developer"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Salesforce Platform Events in Apex Explained<\/title>\n<meta name=\"description\" content=\"Salesforce Platform Events explained simply: event objects, EventBus.publish, publish behaviour, Apex triggers, retries, replay and 21 interview Q&amp;A.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Salesforce Platform Events in Apex Explained\" \/>\n<meta property=\"og:description\" content=\"Salesforce Platform Events explained simply: event objects, EventBus.publish, publish behaviour, Apex triggers, retries, replay and 21 interview Q&amp;A.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/\" \/>\n<meta property=\"og:site_name\" content=\"Swapnil Zambare - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-10T11:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Swapnil Zambare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Swapnil Zambare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/\"},\"author\":{\"name\":\"Swapnil Zambare\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\"},\"headline\":\"Salesforce Platform Events in Apex: Publish and Subscribe\",\"datePublished\":\"2026-09-10T11:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/\"},\"wordCount\":1587,\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/salesforce-platform-events-apex-featured.png\",\"keywords\":[\"Advanced\",\"Apex\",\"Async Apex\",\"Integration\",\"Interview Questions\",\"Salesforce\",\"Salesforce Developer\"],\"articleSection\":[\"Salesforce\",\"Salesforce Developer\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/\",\"name\":\"Salesforce Platform Events in Apex Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/salesforce-platform-events-apex-featured.png\",\"datePublished\":\"2026-09-10T11:30:00+00:00\",\"description\":\"Salesforce Platform Events explained simply: event objects, EventBus.publish, publish behaviour, Apex triggers, retries, replay and 21 interview Q&A.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/#primaryimage\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/salesforce-platform-events-apex-featured.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/salesforce-platform-events-apex-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Salesforce Platform Events featured image: title card with an Apex code example\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/salesforce-platform-events-apex\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Salesforce Platform Events in Apex: Publish and Subscribe\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"name\":\"Swapnil Zambare - Blog\",\"description\":\"Salesforce &amp; Tech Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#organization\",\"name\":\"Swapnil Zambare - Blog\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"contentUrl\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/site-icon-512.png\",\"width\":512,\"height\":512,\"caption\":\"Swapnil Zambare - Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/theSwapnilZambare\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/#\\\/schema\\\/person\\\/922ac0131aaa7088c78c2cb1700e0c9a\",\"name\":\"Swapnil Zambare\",\"sameAs\":[\"https:\\\/\\\/swapnilzambare.com\\\/blog\"],\"url\":\"https:\\\/\\\/swapnilzambare.com\\\/blog\\\/author\\\/swapnil-zambare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Salesforce Platform Events in Apex Explained","description":"Salesforce Platform Events explained simply: event objects, EventBus.publish, publish behaviour, Apex triggers, retries, replay and 21 interview Q&A.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/","og_locale":"en_US","og_type":"article","og_title":"Salesforce Platform Events in Apex Explained","og_description":"Salesforce Platform Events explained simply: event objects, EventBus.publish, publish behaviour, Apex triggers, retries, replay and 21 interview Q&A.","og_url":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/","og_site_name":"Swapnil Zambare - Blog","article_published_time":"2026-09-10T11:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-featured.png","type":"image\/png"}],"author":"Swapnil Zambare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Swapnil Zambare","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/#article","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/"},"author":{"name":"Swapnil Zambare","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a"},"headline":"Salesforce Platform Events in Apex: Publish and Subscribe","datePublished":"2026-09-10T11:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/"},"wordCount":1587,"publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-featured.png","keywords":["Advanced","Apex","Async Apex","Integration","Interview Questions","Salesforce","Salesforce Developer"],"articleSection":["Salesforce","Salesforce Developer"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/","url":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/","name":"Salesforce Platform Events in Apex Explained","isPartOf":{"@id":"https:\/\/swapnilzambare.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/#primaryimage"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/#primaryimage"},"thumbnailUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-featured.png","datePublished":"2026-09-10T11:30:00+00:00","description":"Salesforce Platform Events explained simply: event objects, EventBus.publish, publish behaviour, Apex triggers, retries, replay and 21 interview Q&A.","breadcrumb":{"@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/#primaryimage","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-featured.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/11\/salesforce-platform-events-apex-featured.png","width":2400,"height":1260,"caption":"Salesforce Platform Events featured image: title card with an Apex code example"},{"@type":"BreadcrumbList","@id":"https:\/\/swapnilzambare.com\/blog\/salesforce-platform-events-apex\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/swapnilzambare.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Salesforce Platform Events in Apex: Publish and Subscribe"}]},{"@type":"WebSite","@id":"https:\/\/swapnilzambare.com\/blog\/#website","url":"https:\/\/swapnilzambare.com\/blog\/","name":"Swapnil Zambare - Blog","description":"Salesforce &amp; Tech Guides","publisher":{"@id":"https:\/\/swapnilzambare.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/swapnilzambare.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/swapnilzambare.com\/blog\/#organization","name":"Swapnil Zambare - Blog","url":"https:\/\/swapnilzambare.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","contentUrl":"https:\/\/swapnilzambare.com\/blog\/wp-content\/uploads\/2026\/09\/site-icon-512.png","width":512,"height":512,"caption":"Swapnil Zambare - Blog"},"image":{"@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/in\/theSwapnilZambare"]},{"@type":"Person","@id":"https:\/\/swapnilzambare.com\/blog\/#\/schema\/person\/922ac0131aaa7088c78c2cb1700e0c9a","name":"Swapnil Zambare","sameAs":["https:\/\/swapnilzambare.com\/blog"],"url":"https:\/\/swapnilzambare.com\/blog\/author\/swapnil-zambare\/"}]}},"_links":{"self":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/comments?post=1628"}],"version-history":[{"count":0,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/posts\/1628\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media\/1625"}],"wp:attachment":[{"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/media?parent=1628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/categories?post=1628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/tags?post=1628"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/swapnilzambare.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=1628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}