Platform Events in Salesforce (2/2)
Now, that we have seen basics of Platform Events and Event-Driven Architecture, let's dive in deep to understand Platform Event object and supported field types.
Create a Platform Event :
Step 1: Go to Setup and find Platform Events.
Step 2: Click on New Platform Event Button
Step 3: Fill in all the details and click Save. Let's understand some features of the Platform Event object and fields.
Platform Event Object :
- Plateform Event object is created just like custom objects whose API Name will end with __e.
- Unlike custom objects, we can not view/update/delete event record from UI.
- Platform Event records can not be queried using SOQL.
- Platform Event records can not used in reports and dashboards.
- User can not roll back published event.
- All the fields of Platform Event record would be read only by default.
Platform Event Fields :
- Though the Platform Event object is mostly like any other custom object, there are some limitations on supported field types. It can only support these field types:
- CheckBox
- Date
- DateTime
- Number
- Text
- TextArea
- Publish Behavior : It is a standard picklist field which gives users option to publish event immediately or After commit.
- Publish Immediately : Platform Event will be pushed to Event bus immediately after triggerring an event (Button Click/ Status Change) etc.
- Publish After Commit : Platform Event will get fired after completing all the events from Order of Execution. Use this when you want to send Id of the record as part of event message.
- ReplayId : Salesforce created a field called ReplayId after you create/publish Platform Event Record.
- This is an system generated Id which will always be higher that previous event but not necessarly consecutive.
- It refers to the position of event in the Event Bus.
- Salesforce stores ReplyId in EventBus for 24 hours.
- Subscribers can store ReplayId and use it on resubscription to events those are in retention window.
Publish Platform Event :
We have seen how can we publish platform events in the last Blog. We will use the apex class to publish our event. We will pass CaseId from After Insert trigger on Case.
Subscribe to the Event :
We use process builder/Flow/Apex trigger to subscribe to the Event. We can write triggers in After Insert context only if we are choosing a trigger to subscribe to an Event.
References:





