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
uHaveOptionsuHaveOptions 

Error Performing Open Execute Anonymous Window Update AllRecords

Hello All,

I currently have this APEX Trigger which i am tryng to perform a Update records so the field populates properly.  I am performing a Open Execute in the developer console but getting an error..

trigger MyLastCallDate on Task (after insert, after update, after delete) 
{
    public String currentUser = UserInfo.getUserId();
    public String oldUser=[select old_ID__c from User where id=:currentUser limit 1]
 [0].old_ID__c;
    Set<Id> con_set = new Set<Id>();
    List<Contact> con_list = new List<Contact>();
    for( Task T: Trigger.new )
    {

        {
            con_set.add(T.whoid);
        }
    }
     
     for(AggregateResult aggregateResult:[SELECT max(createdDate)MaxCDate,whoid FROM Task WHERE whoid IN: con_set AND Status ='Completed' AND (subject LIKE 'call%' OR subject LIKE 'outbound%') AND (CreatedbyId=:currentUser OR OLDOWNERID__C=:oldUser) group By whoid])
     {
        con_list.add(new Contact(Id=(id)aggregateResult.get('whoid'),My_Last_Call__c=date.valueof(aggregateResult.get('MaxCDate'))));
        
     }
     
      try
    {
     
         if(con_list !=null && con_list.size()>0)
         {
             update con_list;
         }
     
    }Catch(Exception ee){
         system.debug('Exception ***'+ee.getMessage());
      
     }

}

Error:
Line: 2, Column: 14
No such column 'My_Last_Call__c' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.


Any advise to fix that issue?
Sumit Kumar Singh 9Sumit Kumar Singh 9
Jon Jon, 

Did you write the trigger on Developer Console??? If yes, then it's wrong,  you can't write triiger on Developer console. Only the statements can be executed from the developer console. 

What you can do - 
1) Write this trigger on the task Object. 
2) Create a dummy field on task - Let's say "One time update" : data type - Checkbox.

On the Developer console, execute this script - 
List<task> taskListToUpdate = new List<task>();
for(Task t : [select id, One_time_update__c from Task]) {
	t.One_time_update__c = true; 
    taskListToUpdate.add(t);
}
update taskListToUpdate;
After successful, execution delete the field "One time update" from task.

Hope, it will help you. 

Thanks,
Sumit Kumar Singh
Prakash@SFDCPrakash@SFDC
Hi Jon,

You are referring "My_Last_Call__c" in your trigger . As this field should exist on contact about , Check your object once.
uHaveOptionsuHaveOptions
Thanks Sumit but I'm kinda confised whats the purpose of the checkbox for
Sumit Kumar Singh 9Sumit Kumar Singh 9
It's a dummy field just to update the records. We are not touching any real data, just to avoid mistakes. By chance if something goes wrong,then still we will be safe state, because we are not altering any real data.
That's the purpose. 

Thanks,
Sumit Kumar Singh 
uHaveOptionsuHaveOptions

Ok I created the field in Task and it's in the Layout.  It gave me this error after putting a limit

 

Line: 6, Column: 1
System.LimitException: Too many DML rows: 10001

thoughts?

Sumit Kumar Singh 9Sumit Kumar Singh 9
Yes, because we are trying to update more than 10K records at once. We can update maximum of 10K records at one shot. 
Now, Here one more role of check box comes into picture. 
We can put where clause on this checkbox to get the remaining records to be updated. 
Let's say, you have total 100K records in the Task, then run this script 10 times to update all the records.
List<task> taskListToUpdate = new List<task>();
for(Task t : [select id, One_time_update__c from Task where One_time_update__c = false Limit 10000]) {
	t.One_time_update__c = true; 
    taskListToUpdate.add(t);
}
update taskListToUpdate;
Let me know if it helps you. 

Thanks, 
Sumit Kuamr Singh
uHaveOptionsuHaveOptions

It's giving me this error.

Line: 24, Column: 1
System.LimitException: Too many DML rows: 10001

hahaha im pulling my hair

uHaveOptionsuHaveOptions
I lowered the limit and it was successful.  Now I just need to test and look if it does update.

hahaha but after running it the second time it gave me System.LimitException: Apex CPU time limit exceeded
Sumit Kumar Singh 9Sumit Kumar Singh 9
It's not from the script. It's from your trigger. Try to put limit 5000.
uHaveOptionsuHaveOptions
I lowered it down so now I get...

Line: 9, Column: 1
System.LimitException: Apex CPU time limit exceeded
Sumit Kumar Singh 9Sumit Kumar Singh 9
You can try to lower down the limit 2000. 
OR you can write a batch to update the records. After successful audation you can delete the batch.
uHaveOptionsuHaveOptions
It's giving me APEX limit.  How would I write this batch?