Platform Events in Salesforce

Use platform events to define the data to be delivered in custom notifications.

Use Salesforce Platform Events to connect business processes in Salesforce and external apps through the exchange of real-time event data. Salesforce Platform events are secure and scalable messages that contain data. Publishers publish event messages that subscribers receive in real time. To customize the data published to the external apps, define Platform Event fields.

1. Go to Platform Events.

2. Click New Platform Event.

3. Save Platform Event.

4. Create fields as below.

Sample Trigger:

trigger OrderEventTrigger on Order_Event__e (after insert) {   

    List < Task > listTasks = new List < Task >();
    for (Order_Event__e event : Trigger.New) {

        if (event.Has_Shipped__c == true) {

            // Create Case to dispatch new team.
            Task tsk = new Task();
            tsk.Status = 'New';
            tsk.Priority = 'Medium';
            tsk.Subject = 'Follow up on shipped order ' + 
                event.Order_Number__c;
            tsk.OwnerId = UserInfo.getUserId();
            listTasks.add(tsk);

        }

   }

   insert listTasks;

}

OrderEventTrigger is subscribed to Order Event. If Order Event record is created with Has Shipped equal to create, it will create a task as per the trigger.

Leave a Reply