Skip to main content
Can anyone help me to find out error. 

Below is the error i got.

Review all error messages below to correct your data.

Apex trigger Agentenddatetrigger caused an unexpected exception, contact your administrator: Agentenddatetrigger: execution of AfterInsert caused by: System.TypeException: Invalid id value for this SObject type: a062w000003bp21AAA: Trigger.Agentenddatetrigger: line 11, column 1

code;

trigger Agentenddatetrigger on Agent__c (after insert) 

{

 List<Task__c> taskList = new List<Task__c>();

    

    for(Agent__c age: Trigger.new)

    {

        if(Age.End_Date__c < Date.Today())

        {

            Task__c t = new Task__c();

            t.Subject__c = 'Folow up Task';

            t.Id = age.Id;

            taskList.add(t);

        }

     }

    if(taskList.size()>0)

    {

        Insert taskList;

    }

}
3 个回答
  1. 2020年7月14日 18:05
    Hi,

    Can you please try the below code:

     

    trigger Agentenddatetrigger on Agent__c (after insert) 

    {

    List<Task> taskList = new List<Task>();

    for(Agent__c age : Trigger.new){

    if(age.End_Date__c< Date.Today()){

    Task newTask = new Task(whatID = age.ID, Subject='Follow Up Test Task');

    //A task is created with Opportunity ID and with the subject.

    taskList.add(newTask);

    }

    }

    if(taskList.size()>0){

    insert tasklist;

    }

    }

    ​​​​​​​Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.

    Warm Regards,

    Shirisha Pathuri
0/9000