+ Start a Discussion
CindyCindy 

Apex Trigger to Create Follow Up Task

I am new to apex and i am attempting to create an apex trigger that when a user enters a follow up date on the log a call action, create a task where the status is "not started" and the due date is the Follow up date on the call.

This is what i have so far and it is creating 2 tasks. What should i change to resolve this?
 
trigger CreateFollowUpTask on Task (after insert, after update) {
	Task[] oTasks = new List<Task>();
    for (Task C : trigger.new ) {
        if (C.Follow_Up_Date_Time__c !=null){
            oTasks new Task(Subject='Follow up', ActivityDate=C.Follow_Up_Date_Time__c,Status='Not Started',OwnerId=C.OwnerId,WhatId=C.WhatId,WhoId=C.WhoId));
        }
    }
   insert oTasks;

}


 
mukesh guptamukesh gupta
Hi Cyndie,

Please use below code:-
 
trigger CreateFollowUpTask on Task (after update) {
	Task[] oTasks = new List<Task>();
    for (Task C : trigger.new ) {
        if (C.Follow_Up_Date_Time__c !=null){
            oTasks new Task(Subject='Follow up', ActivityDate=C.Follow_Up_Date_Time__c,Status='Not Started',OwnerId=C.OwnerId,WhatId=C.WhatId,WhoId=C.WhoId));
        }
    }
   insert oTasks;

}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
CindyCindy
Thank you Mukesh, I entered used the code and got an error
User-added image

Expression cannot be a statement.