You need to sign in to do that
Don't have an account?

Trigger to Create Event from Task
I am trying to write a trigger, that will, in effect turn a task into an event in sfdc as follows:
1. Make a check box on task (Custom field called "turn into event")
2. When checkbox is checked, a trigger is activated to create a new event.
3. This event is populated with the data from the task that starts it.
4. Then the old task is deleted.
Thanks in advance
Hi,
I have written a small trigger for this made changes accordingly. You can write your trigger for bulk handling.Please go through this code as reference:
trigger CreateEvent on Task (after insert,after update)
{
task ta=trigger.new[0];
if(ta.CreateEvent__c==true)
{
task ta1=trigger.old[0];
Datetime startDateTime=Datetime.newInstance(ta1.activitydate, Time.newInstance(12, 0, 0, 0));
Datetime endDateTime=Datetime.newInstance(ta1.activitydate, Time.newInstance(12, 0, 0, 0));
Event e=new event(OwnerId = ta1.ownerid,Subject = ta1.Subject,StartDateTime = startDateTime,EndDatetime = endDateTime,WhoId = ta1.whoid);
insert e;
task t=new task(id=ta1.id);
delete t;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
I have written a small trigger for this made changes accordingly. You can write your trigger for bulk handling.Please go through this code as reference:
trigger CreateEvent on Task (after insert,after update)
{
task ta=trigger.new[0];
if(ta.CreateEvent__c==true)
{
task ta1=trigger.old[0];
Datetime startDateTime=Datetime.newInstance(ta1.activitydate, Time.newInstance(12, 0, 0, 0));
Datetime endDateTime=Datetime.newInstance(ta1.activitydate, Time.newInstance(12, 0, 0, 0));
Event e=new event(OwnerId = ta1.ownerid,Subject = ta1.Subject,StartDateTime = startDateTime,EndDatetime = endDateTime,WhoId = ta1.whoid);
insert e;
task t=new task(id=ta1.id);
delete t;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thank you very much - You Are a Genious !!!!
Small Question - how do i make the "all day event" box be checked instead of based on a time ?
Thanks in advance
I am getting this error....Help: