Platform Events in Salesforce

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

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.

Cheers!!!

No comments:

Post a Comment