• rburns
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

 I'm trying to create a task in the same screen as the opportunity using the trigger below. When I use this in the Lead object it works fine but on the opportunity object it doesn't create the task nor gives me an error. Can anyone see where my error may lie?

 

Thx.

 

trigger taskCreator on Opportunity (before insert, before update, after insert) {
  if (Trigger.isBefore) { 
    Map<Id, Opportunity> opportunityMap = new Map<Id, Opportunity>();


 } else if (Trigger.isAfter)  { 
    // after leads are inserted
    List<Task> followupTasks = new List<Task>(); // build list in memory
    for (Opportunity opp : System.Trigger.new) {
        Task task = new Task(
          //WhoId = opp.Assigned_To__c, 
          //Description = opp.Synopsis__C, 
          Priority = 'High', 
          ReminderDateTime = opp.Due_Date__C, 
          Status = 'Not Started', 
          Subject = opp.Quick_Task_Subject__c);
        followupTasks.add(task);   // add to list
    }

        // insert the entire list
    insert followupTasks;  // NOTE: this is outside the above loop, only one insert is needed

 } // end of isAfter

}// end of trigger