Subscribing to and handling platform events
One of the key features of platform events is that we can subscribe to and then act upon an event from a variety of different solutions. In this section, we are going to talk through the available solutions on the Salesforce platform itself before looking at handling events off-platform in the next section.
Handling platform events using Apex triggers
For Apex developers, the simplest way to subscribe to a platform event channel in Apex is to use a trigger on the platform event. Triggers defined for a platform event can only operate in the after insert
context since no other context exists for an event. In the following code snippet, you can see a simple trigger for our Demonstration__e
platform event:
trigger DemonstrationTrigger on Demonstration__e (after insert) { for(Demonstration__e demo : (List<Demonstration__e>) Trigger.new...