+ Start a Discussion
Aaditya SinghAaditya Singh 

Hi I am trying to below code but i am getting error Comparison arguments must be compatible types: Schema.SObjectField, Date... bu End_Date__c is also date type

trigger autoCreateTaskAgent on Agent__c (after insert) {
List <Task> autoTask = new List <Task>();
    List <Agent__c> agentList = new List <Agent__c>();
    //Date today1 = Date.today();
    if(Agent__c.End_Date__c < Date.today())
    {
        System.debug('Hello');
    }
}
Best Answer chosen by Aaditya Singh
@anilbathula@@anilbathula@
Hi Aaditya,

Try this code,there might be typo errors plese check once.
 
trigger autoCreateTaskAgent on Agent__c (after insert) {
List <Task> autoTask = new List <Task>();
    for(Agent__c ag:trigger.new){
		if(ag.End_Date__c <system.today()){
				task t=new task();
				t.OwnerId = ag.OwnerId;
				t.Subject = 'Call';
				t.Priority = 'Normal';
				t.Status = 'Not Started';  
               // add other fields which you want to populate on task              
				autoTask.add(t);  
		 
		}
	}
   if(!autoTask.isempty())
   insert autoTask;
}

 

All Answers

Aaditya SinghAaditya Singh
my requirement is as belo
  1. Create a trigger by using the following algorithm(Custom Task  on the Custom Object can be achieved only with the help of Triggers)
  • Create an After Insert Trigger on Agent Object.
  • Create a Task List.
  • If Agent.EndDate < Today
  1. Create the Task object.
  2. Add these Task objects to Task List.
  • Insert the task List.
@anilbathula@@anilbathula@
Hi Aaditya,

Try this code,there might be typo errors plese check once.
 
trigger autoCreateTaskAgent on Agent__c (after insert) {
List <Task> autoTask = new List <Task>();
    for(Agent__c ag:trigger.new){
		if(ag.End_Date__c <system.today()){
				task t=new task();
				t.OwnerId = ag.OwnerId;
				t.Subject = 'Call';
				t.Priority = 'Normal';
				t.Status = 'Not Started';  
               // add other fields which you want to populate on task              
				autoTask.add(t);  
		 
		}
	}
   if(!autoTask.isempty())
   insert autoTask;
}

 
This was selected as the best answer
Aaditya SinghAaditya Singh
Thanks .. now it is working fine. I want to know more about this. Contaxet Trigger.new is always required for using the fields of an object on which trigger has been written?