This website uses cookies. By continuing to browse the site, you are agreeing to our use of cookies
Customer Experience
June 28, 2018
Salesforce introduced Platform Events as a part of Summer’17 release. The Salesforce platform events are addition to other Salesforce integration capabilities such as Outbound Messaging, Apex Callouts and Streaming API. Considering that companies can no longer work solely with one application, this native feature provides an event-driven messaging architecture, enabling apps to communicate inside and outside of Salesforce.
There are five main components:
End users are interacting with companies through multiple channels like web, mobile, customer care centers, social media and so on. Behind all these channels, there may be multiple systems which are not necessarily in sync for customer data at all times. But customer expects to see correct and same information across multiple channels. This demands real-time sync between various systems to keep customer data up-to-date. Salesforce Platform events capability is based on event-driven messaging architecture which enables Salesforce to send out information to external system when event occurs or consume event published by external system. This capability is beneficial in scenarios where such information sync is required in an application echo system where Salesforce is the key system.
Event-based (message-driven) communication involves event publisher and event consumer. Events are sent regardless of consumer listening or not. Consumers don’t acknowledge it when they receive an event. Event-based communication takes place in near-real time. Key component of event-driven architecture are Event Producer, Event Consumer, Event Channel, Event Message and Event. . The architecture is works well for large distributed systems as it decouples event producers from event consumers, thus simplifying the communication model in connected systems. An event-driven architecture helps in avoidance of point-to-point integration. It offers scalability and avoids tight coupling between systems.
Platform events enables bi-directional real-time integrations based on events. Salesforce can either act as an event producer or consumer.
Here are examples of business scenarios where platform events can be used:
Salesforce as Event Producer: Salesforce sends out notification to an external order fulfillment app about product shipment order.
Salesforce as Event Consumer: External order fulfillment app sends notification on shipment status for an Order.
Setting up platform event in Salesforce is very similar to creating custom object. The API name of platform event ends with ‘__e’.
To create a Platform event, follow the steps below.
Field types supported by Platform events are Checkbox, Date, Date/Time, Number, Text, and Text Area (Long).
The events are stored by Salesforce for 24-hour period. Each event is assigned an ID in ReplayID system field. You cannot query events through SOQL or SOSL. You can see event records in reports, list views and search. You can retrieve past events only when subscribing in CometD and using a ReplayId option.
From Salesforce, you can publish events using an Apex method or with declarative tools, like Process Builder or Flow.
To publish event messages, you create an instance of the event and pass it to the EventBus.publish method.
// Create an instance of the event Sample_Event__e orderEvent = new Sample_Event__e( Order_Number__c =100, Status__c=‘ReadyToShip’ ); // Call method to publish events Database.SaveResult sr = EventBus.publish(orderEvent);
To publish event messages using Process Builder or Flow, you can use the record creation functionality.
External apps use an API to publish platform event messages. You publish events by creating records of your event in the same way that you insert sObjects.
On the Salesforce Platform, following tools allow subscribing to platform events – Apex triggers, processes, and flows.
Apex Triggers: You will need to write an after-insert Apex trigger on the event object to subscribe to incoming events.
Process Builder\Flow: To consume platform event though process builder, you will need to create a process that starts when a platform event occurs.
Customers can run businesses faster on an event-driven architecture
Niraj has extensive experience in Enterprise CRM applications, solution design, architecture and system integrations. 3x Salesforce Certified Professional, AWS Certified Cloud Practitioner and playing role of an application architect in his current assignment.
Niraj Wani
For more insights please feel free to connect with us on marketing@hexaware.com.
About the Author
Niraj Wani
Read more
Every outcome starts with a conversation