Skip to main content
Development

What is Platform Event in Salesforce?

Updated · By the Clientell AI team · How we write

A platform event in Salesforce is a custom message that a publisher sends to the Salesforce event bus so subscribers can react in near real time. Publishers and subscribers never call each other. Apex triggers, flows, Lightning components and external apps can all subscribe. You define the message fields yourself in Setup.

Key facts

What it is
A custom, schema-defined message sent over the Salesforce event bus with publish-subscribe (Platform Events Developer Guide)
API name suffix
__e, for example Order_Shipped__e
Publish with
Apex EventBus.publish(), a flow, REST or SOAP API, Pub/Sub API, external systems
Subscribe with
Apex triggers, flows, Lightning components, Pub/Sub API and CometD clients (Subscribing to Platform Events)
Retention
72 hours, so subscribers can replay missed events (Pub/Sub API Guide)
Where to create one
Setup > Integrations > Platform Events > New Platform Event

Clientell AI, the AI Salesforce admin, builds and fixes Platform Event automation from a plain-English request. See the AI flow builder

Try it in Clientell AI

“Find every Platform Event in my org that touches the Opportunity object, list what each one does, and flag any that conflict.”

Clientell AI reads your org first. Platform deployments include rollback. How security works.

Start the 14-day free trial, no card

What is a platform event in Salesforce?

A platform event is a message with a shape you define. You create it in Setup much like a custom object, with custom fields, and its API name ends in __e. When something happens, a publisher sends one message to the event bus. Every subscriber to that event type receives it (Platform Events Developer Guide).

This is the publish-subscribe pattern. The publisher does not call each subscriber. That keeps systems loosely coupled, so you can add a subscriber later without changing the publisher.

Events are messages, not stored rows. You cannot build a report on them the usual way. If the data must last, a subscriber has to write it to a record. You cannot query an event with SOQL (Salesforce Object Query Language) as you would an Account.

How do you publish and subscribe to platform events?

Publishers and subscribers can sit inside Salesforce or outside it. The table shows the common choices.

RoleOptionsGood for
PublishApex EventBus.publish(), a flow Create Records element on the __e object, REST or SOAP API, Pub/Sub APITelling other systems that a business event happened
Subscribe inside SalesforceApex trigger, platform-event-triggered flow, Lightning component with empApiReacting in Apex or in automation
Subscribe outside SalesforcePub/Sub API, CometD clientsSending the event to an ERP, a data warehouse or middleware

Example: define an event and publish it from Apex or Flow

Say the warehouse must tell other systems when an order ships. First define the event. Then publish it and subscribe to it.

Publishing returns a result for each event, so you can check for errors. The trigger below runs after the event reaches the bus.

  • 1. From Setup, enter Platform Events in the Quick Find box and select Platform Events.
  • 2. Click New Platform Event. Set the label to Order Shipped. The API name becomes Order_Shipped__e.
  • 3. Under Publish Behavior, choose Publish After Commit, then Save.
  • 4. In Custom Fields & Relationships, add Order_Number__c (Text) and Carrier__c (Text).
  • 5. To publish from a flow, add a Create Records element and select Order_Shipped__e. To publish from Apex, use the code below.
// Publish
Order_Shipped__e evt = new Order_Shipped__e(
    Order_Number__c = 'SO-1001',
    Carrier__c = 'DHL'
);
Database.SaveResult sr = EventBus.publish(evt);
if (sr.isSuccess() == false) {
    for (Database.Error err : sr.getErrors()) {
        System.debug('Publish failed: ' + err.getMessage());
    }
}

// Subscribe: a trigger on the event object
trigger OrderShippedTrigger on Order_Shipped__e (after insert) {
    for (Order_Shipped__e e : Trigger.new) {
        System.debug('Shipped: ' + e.Order_Number__c + ' via ' + e.Carrier__c);
    }
}

Publish immediately or after commit: which should you pick?

You choose the publish behavior when you define the event. Publish Immediately is the default. It sends the event when the publish call runs, even if the transaction later fails. A subscriber can then receive the event before the data is committed. Publish After Commit sends the event only after the transaction commits, and never if it fails (Salesforce Help: Define and Manage Platform Events).

Pick After Commit when the subscriber needs the saved data, for example a task record the publisher just created. Pick Immediately when the event must go out regardless, such as for logging.

A subscriber trigger runs in its own transaction. It does not run as the user who published the event. Plan permissions and record ownership for that.

Platform events vs Change Data Capture

Both use the event bus. The difference is who writes the message. Salesforce retains change events for 72 hours as well (Change Data Capture Allocations).

Platform eventChange Data Capture
Who creates the messageYou, with your own fieldsSalesforce, when a record is created, updated, deleted or undeleted
PayloadWhatever you defineThe changed fields of the record
What triggers itYour code or flow decides whenA data change on a selected object
Best forBusiness events and system messagesKeeping an outside copy of Salesforce data in sync

What are the platform event limits and replay rules?

Each event gets a replay ID that marks its place in the stream. A subscriber stores the last ID it handled and, if it goes offline, resumes from there within the retention window. Salesforce keeps events for 72 hours (Pub/Sub API Guide).

For allocations, Enterprise and Unlimited Editions can publish 250,000 events per hour by default. Delivery to Pub/Sub API and CometD clients is 50,000 per 24 hours in Unlimited Edition and 25,000 in Enterprise Edition. Apex triggers and flows do not count against the delivery allocation (Platform Event Allocations). Check your own figures in Setup, since add-ons change them.

Older standard-volume events (API version 44.0 and earlier) are retired in Summer ’27. You cannot define new ones (Standard-Volume Allocations).

FAQ: Platform Event in Salesforce

What is a platform event in Salesforce?

A custom message you define in Setup and publish to the Salesforce event bus. Subscribers such as Apex triggers, flows and external apps receive it in near real time.

What is the Salesforce event bus?

The event bus is the channel that carries platform events and change events. Publishers write to it and subscribers read from it. Events stay for a set window so subscribers can replay them.

When should I use a platform event?

Use one to tell other systems or automations that something happened, without calling them directly. It fits integrations, error logging and fan-out to several subscribers.

How long are platform events stored?

72 hours. Salesforce does not guarantee storage beyond that window (Pub/Sub API Guide).

Are platform events the same as Change Data Capture?

No. With a platform event you define the message and decide when to send it. With Change Data Capture, Salesforce sends a message every time a selected record changes.

Can a flow publish and subscribe to platform events?

Yes. A flow can publish with a Create Records element, and a platform-event-triggered flow can subscribe (Salesforce Developers).

Getting Started

Try this on your own org

Start the 14-day free trial, no card. Clientell AI asks before it changes anything in production.

14-day free trial  ·  No credit card required

SOC 2
HIPAA
ISO 27001
Salesforce Partner