New to Apex development so I wouldn't be surprised if I'm missing something obvious here. Anyways I'm trying to write a trigger that adds a task to an opportunity once it is created (and sets the due date to be six months in the future). Here's what I have:
trigger FollowUp on Opportunity (after insert) {
List<Task> taskList = new List<Task>();
for (Opportunity Opp: trigger.new) {
Task t = new Task();
t.whatID = opp.ID;
t.Subject = 'Follow up with Report';
Date dueDate = opp.CloseDate;
t.ActivityDate = dueDate.addmonths(6);
taskList.add(t);
}
}
However, after I save this, I have tried creating a new opportunity, and no task is created.
My two questions are:
1) What is wrong with this specific code, why is it not creating a new task on the donation?
2) In the future, what tools are available to me in SF to diagnose why Apex code is not working? Are errors saved anywhere?
Thank you very much!
insert taskList;
after the for loop. You could refer this: Apex best practices as a start for your Apex development.