Understanding Platform Events in Salesforce with a Real Use Case

🚀 Understanding Platform Events in Salesforce with a Real Use Case

In today’s world of real-time business processes, organizations can’t rely on batch updates or manual notifications alone. Systems need to communicate instantly and seamlessly. That’s where Platform Events in Salesforce come in.

Platform Events are part of the Salesforce Event-Driven Architecture (EDA). They enable pub/sub (publish-subscribe) communication both inside Salesforce and with external systems, making them a powerful tool for building scalable and loosely coupled applications.

🔹 What are Platform Events?

Platform Events are similar to custom objects in Salesforce, but instead of storing data permanently, they are designed to deliver event messages.

  • Publishers send events when something happens.
  • Subscribers listen and respond to those events in real time.

👉 Think of Platform Events as a messaging bus inside Salesforce, where different systems and processes can talk to each other asynchronously.

🔹 Key Characteristics of Platform Events
  1. Schema-based – You define custom fields just like on objects.
  2. Immutable – Once published, an event record cannot be changed.
  3. Publish/Subscribe Model – Multiple subscribers can act on the same event independently.
  4. Delivery Options:
    • Publish Immediately (committed instantly)
    • Publish After Commit (sent only after the transaction is successful)
  5. Integration Friendly – Events can be consumed by Apex triggers, Flows, Process Builder, CometD clients, or external systems.
🔹 When to Use Platform Events?

Platform Events are best suited when:

  • You want real-time communication between apps.
  • You need asynchronous processing of data.
  • You want to decouple systems (so one process doesn’t depend on another).
  • You’re integrating Salesforce with external apps (ERP, middleware, data warehouses, etc.).
🔹 Real-World Use Case

Scenario: Automatic Notification to External System When a Case is Escalated

Imagine a support team using Salesforce Cases. Whenever a Case is escalated, we want to notify an external incident management system (like ServiceNow or Jira) in real time without manual intervention.

Step 1: Define a Platform Event

Let’s create a Platform Event called Case_Escalation_Event__e.

Fields:

  • CaseId__c (Text 18) → to store the Salesforce Case Id
  • CaseNumber__c (Text 30) → Case Number
  • Priority__c (Text 20) → Priority of the case
  • EscalatedBy__c (Text 50) → Who escalated the case
Step 2: Publish the Event

We publish this event whenever a case is escalated. This can be done in Apex, Flow, or Process Builder.

Example in Apex:

Case_Escalation_Event__e caseEvent = new Case_Escalation_Event__e(

CaseId__c = caseRecord.Id,

CaseNumber__c = caseRecord.CaseNumber,

Priority__c = caseRecord.Priority,

EscalatedBy__c = UserInfo.getUserName()

);

Database.SaveResult result = EventBus.publish(caseEvent);

if (result.isSuccess()) {

System.debug(‘Event published successfully’);

} else {

System.debug(‘Failed to publish event’);

}

Step 3: Subscribe to the Event

Inside Salesforce

  • Use a Platform Event-triggered Flow to perform actions (like sending an email).
  • Use Apex Trigger to process the event.

Example Apex Subscriber:

trigger CaseEscalationSubscriber on Case_Escalation_Event__e (after insert) {

for (Case_Escalation_Event__e eventRecord : Trigger.New) {

System.debug(‘Escalated Case: ‘ + eventRecord.CaseNumber__c);

// Example: create a Task to notify support manager

Task t = new Task(

Subject = ‘Escalated Case Notification’,

WhatId = eventRecord.CaseId__c,

Description = ‘Case ‘ + eventRecord.CaseNumber__c +

‘ with priority ‘ + eventRecord.Priority__c +

‘ was escalated by ‘ + eventRecord.EscalatedBy__c,

Status = ‘Not Started’,

Priority = ‘High’

);

insert t;

}

}

Outside Salesforce

  • External systems can subscribe using CometD or Streaming API.
  • Example: ServiceNow can listen for Case_Escalation_Event__e and automatically create an incident.
🔹 Benefits of Platform Events in This Use Case

✅ Real-time – External system gets the update instantly.
✅ Decoupled Architecture – Salesforce doesn’t need to wait for ServiceNow/Jira to respond.
✅ Scalability – Multiple subscribers (internal flow + external system) can act on the same event.
✅ Flexibility – Can trigger follow-up actions (emails, tasks, integration calls).

🔹 Best Practices for Platform Events
  1. Use Publish After Commit for data integrity.
  2. Keep payloads lightweight (only send necessary fields).
  3. Implement error handling in subscribers.
  4. Consider Replay IDs if external systems need to reprocess events.
  5. Monitor event usage with Event Monitoring.
🔹 Conclusion

Platform Events are a game-changer for Salesforce integrations. They allow businesses to build event-driven, scalable, and real-time applications. In our use case, we saw how a simple Case Escalation Event can notify both Salesforce users and external systems without manual effort.

👉 Whether you’re integrating with ERP, ticketing tools, or mobile apps, Platform Events ensure smooth, asynchronous communication — keeping your business processes fast, reliable, and future-ready.

 

Leave a Comment

Your email address will not be published. Required fields are marked *