function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Seth PayneSeth Payne 

Error: Compile Error: List index must be of type Integer

Trying to create trigger to create a task when a date is filled in.  Here is what i have so far and getting the error above.

 
trigger CreateTaskonAnnualReport on Annual_Report__c (after update) {
    
    List<Task> newTasks = new List<Task>();
        for (Annual_Report__c ar : Trigger.isupdate()){
            //Creating Task to Matt Sutherland when Certificate Date is updated from null to any value, and he was the initial submitter
            if (Trigger.old[ar].Certificate_Date__c != Trigger.new[ar].Certificate_Date__c
Thoughts on why I am getting this error or any ideas to improve?

Thanks,
Seth

Best Answer chosen by Seth Payne
rohitsfdcrohitsfdc
Seth,
Trigger.isUpdate is a boolean which indicates if this is an update operation.

Try the code below:

trigger CreateTaskonAnnualReport on Annual_Report__c (after update) {
    
    List<Task> newTasks = new List<Task>();
        for (Annual_Report__c ar : Trigger.new){
            //Creating Task to Matt Sutherland when Certificate Date is updated from null to any value, and he was the initial submitter
         if(ar.fieldname != trigger.oldmap.get(ar.id).fieldname){

//your logic here
}




All Answers

rohitsfdcrohitsfdc
Seth,
Trigger.isUpdate is a boolean which indicates if this is an update operation.

Try the code below:

trigger CreateTaskonAnnualReport on Annual_Report__c (after update) {
    
    List<Task> newTasks = new List<Task>();
        for (Annual_Report__c ar : Trigger.new){
            //Creating Task to Matt Sutherland when Certificate Date is updated from null to any value, and he was the initial submitter
         if(ar.fieldname != trigger.oldmap.get(ar.id).fieldname){

//your logic here
}




This was selected as the best answer
Seth PayneSeth Payne
Worked perfectly!

Thanks!