Skip to main content
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;

}

 
2 个回答
  1. 2022年4月14日 05:10
    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 
0/9000