• Scott Song 4
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I cannot complete the Subscribe to Platform Events challenge. When I click the 'Check Challenge' button I get the following error:

Publishing an Order_Event__e did not create the associated task successfully. Please check your trigger and event.

Here is my code:

trigger OrderEventTrigger on Order_Event__e (after insert) {
    // List to hold all tasks to be created.
    List<Task> tasks = new List<Task>();
    
    // Get queue Id for case owner
    String usr = UserInfo.getUserId(); 
        
       
    // Iterate through each notification.
    for (Order_Event__e event : Trigger.New) {
        if (event.Has_Shipped__c == true) {
            // Create Task to dispatch new team.
            Task t = new Task();
            t.Priority = 'Medium';
            t.Status = 'New';
            t.Subject = 'Follow up on shipped order' + event.Order_Number__c;
            t.OwnerId = Usr;
            tasks.add(t);
        }
   }
    
    // Insert all tasks corresponding to events received.
    insert tasks;
}

Please assist. Thanks. 
For the above qus I wrote the below code : 

trigger ClosedOpportunityTrigger on Opportunity (after insert,after update) {

List<Task> t1=new List<Task>();


for (opportunity a :[select ID,StageName  from opportunity where StageName='Closed Won' and ID IN :Trigger.New])
{


t1.add(new Task(subject= 'Follow Up Test Task', WhatId=a.ID));

if(t1.size() >0 && t1.size()<=200)
{
insert t1;
}
}
}



But getting a error like   :
Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trig_conts_opprty: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0 with id 0032800000QkI6aAAF; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id] Trigger.trig_conts_opprty: line 10, column 1: []


Anyone please tell me the possible reason for the error ?