You need to sign in to do that
Don't have an account?
tedevang
Create quick task with opportunity
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
Hi,
Just had a quick look to your code and I think you forgot to set the Task.WhatId field:
Task task = new Task(
//WhoId = opp.Assigned_To__c,
//Description = opp.Synopsis__C,
WhatID = opp.Id;
Priority = 'High',
ReminderDateTime = opp.Due_Date__C,
Status = 'Not Started',
Subject = opp.Quick_Task_Subject__c);
Anyway, I'm not sure why you're doing this via a trigger rather than creating this follow up task via the Workflo.
Hope it helps...
All Answers
Hi,
Just had a quick look to your code and I think you forgot to set the Task.WhatId field:
Task task = new Task(
//WhoId = opp.Assigned_To__c,
//Description = opp.Synopsis__C,
WhatID = opp.Id;
Priority = 'High',
ReminderDateTime = opp.Due_Date__C,
Status = 'Not Started',
Subject = opp.Quick_Task_Subject__c);
Anyway, I'm not sure why you're doing this via a trigger rather than creating this follow up task via the Workflo.
Hope it helps...
Actually I have a followup question and issue. Below is the current trigger which works as it is written. Here is what I need:
OK - I had an uppercase "C" in Due_Date__c so that's fixed. Now I would like to just reset all the Opportunity custom fields related to Quick Task. How would I do that?
Thanks.
Spoke too soon.
On ActivityDate = opp.Due_Date__c
I get this error: Invalid initial expression type for field Task.ActivityDate, expecting: Date at line 12 column 26. Do I need to specify somewhere that this is a date/time field?
Hello,
I've just stumbled across this post and is something that I would love to employ.
Can you tell if you managed to perfect this??
Richard.