+ Start a Discussion
Manu Mahajan 22Manu Mahajan 22 

Subscribe to Platform Events- Trailhead Error

Hi I am getting follwoing Error for Trailhead- "Challenge Not yet complete... here's what's wrong: 
Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event."

Following is the code create by me:
trigger OrderEventTrigger on Order_Event__e (after insert) {
    
    List<Task> tasks = new List<Task>();
    
    // Get queue Id for case owner
    User usr = [SELECT Id FROM User WHERE Username='manumars10@gmail.com'];
       
    // Iterate through each notification.
    for (Order_Event__e event : Trigger.New) {
        if (event.Has_Shipped__c == true) {
            // Create Case to dispatch new team.
            Task task=new Task();
            task.WhatId = event.ReplayId;
            task.WhoId = usr.Id;
            task.Subject = 'Follow up on shipped order ' + event.Order_Number__c;
            task.priority= 'Medium';
            task.status = 'New';
           // task.description = 'New  Work';     
            tasks.add(task);
        }
   }
    
    // Insert all cases corresponding to events received.
    insert tasks;

}
Best Answer chosen by Manu Mahajan 22
Raj VakatiRaj Vakati
Hi Manu ,
code is herer
trigger OrderEventTrigger on Order_Event__e (after insert) {
    
    List<Task> tasks = new List<Task>();
    for (Order_Event__e event : Trigger.New) {
        if(event.Has_Shipped__c == true){
            Task t = new Task();
            t.Priority='Medium';
            t.Status='New';
            t.Subject='Follow up on shipped order '+event.Order_Number__c ; 
            t.OwnerId =Userinfo.getUserId() ;
            tasks.add(t);
        }
    }
    
    insert tasks ;
    
}