• amaya sydney
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi - when doing the challenge "Bulk Apex Trigger" in Trailhead I get the error message :"Executing against the trigger does not work as expected."

I have checked the name of the class, task name as mentioned in the challenge description.

I have copied the code below :

trigger ClosedOpportunityTrigger on Opportunity (before insert, before update) {
  List<Task> taskList = new List<Task>();

    //If an opportunity is inserted or updated with a stage of 'Closed Won'
    // add a task created with the subject 'Follow Up Test Task'.
    for (Opportunity opp : [SELECT Id,Name FROM Opportunity
                     WHERE Id IN :Trigger.new AND StageName = 'Closed Won']) {
       //add a task with subject 'Follow Up Test Task'.
       taskList.add(new Task(Subject='Follow Up Test Task', WhatId = opp.id ));                
  }
                          
    if (taskList.size() > 0) {
        insert taskList;
    }



Thank you
Pierre-Alain