To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'. The Apex trigger must be called 'ClosedOpportunityTrigger' With 'ClosedOpportuni
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update)
{
List<Task> taskListToInsert = new List<Task>();
for(Opportunity o: Trigger.new)
{
if(o.StageName=='Closed Won' && ( trigger.isInsert || (trigger.isUpdate && trigger.oldMap.get(o.Id).StageName != 'Closed Won') ))
{
Task t= new Task();
t.Subject='Follow up Task';
t.WhatId=o.Id;
taskListToInsert.add(t);
}
}
if(taskListToInsert.size() > 0){
insert taskListToInsert ;
}
}
I am getting an error 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.LimitException: Too many DML statements: 151