Reader small image

You're reading from  Mastering Apex Programming

Product typeBook
Published inNov 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781800200920
Edition1st Edition
Languages
Right arrow
Author (1)
Paul Battisson
Paul Battisson
author image
Paul Battisson

Paul Battisson is the CEO of Groundwork Apps, a Salesforce ISV Partner, a 9- time Salesforce MVP, and a current MVP Hall of Fame member. He has spoken at numerous Salesforce events including Dreamforce, London's Calling, the Salesforce London World Tour, India Dreamin, and DreamOle. He runs the Leeds Developer Group in the UK and the CloudBites TV website and YouTube channel where he helps Salesforce developers, consultants, admins and architects. He is the author of multiple books and training courses on Salesforce programming.
Read more about Paul Battisson

Right arrow

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, as 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) {
        ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering Apex Programming
Published in: Nov 2020Publisher: PacktISBN-13: 9781800200920

Author (1)

author image
Paul Battisson

Paul Battisson is the CEO of Groundwork Apps, a Salesforce ISV Partner, a 9- time Salesforce MVP, and a current MVP Hall of Fame member. He has spoken at numerous Salesforce events including Dreamforce, London's Calling, the Salesforce London World Tour, India Dreamin, and DreamOle. He runs the Leeds Developer Group in the UK and the CloudBites TV website and YouTube channel where he helps Salesforce developers, consultants, admins and architects. He is the author of multiple books and training courses on Salesforce programming.
Read more about Paul Battisson