You need to sign in to do that
Don't have an account?
IoniaCorp
Create an additional Task based on the current task
I am trying to create an additional task if the status of the current task is "Left Message". The new task will be identical except its status will be "Not Started", and due date will be different one.
My sample code is as follows:
*****************
trigger CreateNewIfStatusChangedToLeftMessage on Task (after insert,after update) {
for (Task t : Trigger.new) {
if (t.Status=='Left Message')
{
Task task = new Task(
//WhoId = t.WhoId,
// Owner = t.Owner,
// What = t.What,
Description = t.Description,
Priority = t.Priority,
ReminderDateTime = System.now().addDays(2),
ActivityDate = System.Today(), //should be different from the current one
Status = 'Not Started',
Subject = t.Subject);
insert task;
System.debug('Additional Task Created') ;
}
else
{
System.debug('Status: ' + 'Not changed.' ) ;
}
}
}
***************************
From the debugging message the additional task seems to be created. But I am unable to see the new task under the page where I started creating the task. I can see only one task created, not both of them.
Any suggestion will be appreciated.
Thank you.
My sample code is as follows:
*****************
trigger CreateNewIfStatusChangedToLeftMessage on Task (after insert,after update) {
for (Task t : Trigger.new) {
if (t.Status=='Left Message')
{
Task task = new Task(
//WhoId = t.WhoId,
// Owner = t.Owner,
// What = t.What,
Description = t.Description,
Priority = t.Priority,
ReminderDateTime = System.now().addDays(2),
ActivityDate = System.Today(), //should be different from the current one
Status = 'Not Started',
Subject = t.Subject);
insert task;
System.debug('Additional Task Created') ;
}
else
{
System.debug('Status: ' + 'Not changed.' ) ;
}
}
}
***************************
From the debugging message the additional task seems to be created. But I am unable to see the new task under the page where I started creating the task. I can see only one task created, not both of them.
Any suggestion will be appreciated.
Thank you.
I tried to use Owner = t.Owner & What = t.What but I got error Error: Compile Error: Field is not writeable: Owner at line 9 column 28 and so on.
I turned on the Debug Log and saw that the insert is not failing. Only problem is I can not see the additional task in the page. I can see only one instead of two - for the case of Status="Left Message" not for the Status = "Not Started"
It solved my current problem - by making OwnerId and WhatId it works fine.