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
BarryPlumBarryPlum 

Mass update Null Task Types

There is a known issue where Tasks created via Mass Emailing are not set to Type=Email.  I'm trying to develop an Apex class (possibly a custom controller for VF) that will allow me to have someone go in and hit a button that will set all the Nulls to Email for the Tasks created by Mass Email.

 

Here is my code, which works using anonymous execution, however, it came close to the governance limits (10k).

 

public class nullTaskCleanup { for (Task[] badTypes : [select Id, Type from Task where Type=Null AND Subject LIKE '%Email%']) { for(Task t : badTypes) { t.type = 'Email'; } update badTypes; } }

 

 1. Why am I running into governance limits, I thought using the code above would 'chunk' it and avoid this issue.

 

2. When I try to save the above, I get an error saying that it expected a } on the second line.

 

Thanks for any help on this.

Barry

 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

1. The code does 'chunk' the records retrieved in the query, but it still has an upper limit of 10k for # of records retrieved in SOQL queries (if executed in the context of Execute Anonymous).

 

2. Your code defines a class, but no method.  Try something like this (this compiled for me):

 

 

public class nullTaskCleanup {
public void executeMethod(){
for (Task[] badTypes : [select Id, Type from Task where Type=Null AND Subject LIKE '%Email%']) {
for(Task t : badTypes) {
t.type = 'Email';
}
update badTypes;
}
}
}

 

 

 

Message Edited by aalbert on 02-03-2009 03:11 PM
Message Edited by aalbert on 02-03-2009 03:11 PM

All Answers

aalbertaalbert

1. The code does 'chunk' the records retrieved in the query, but it still has an upper limit of 10k for # of records retrieved in SOQL queries (if executed in the context of Execute Anonymous).

 

2. Your code defines a class, but no method.  Try something like this (this compiled for me):

 

 

public class nullTaskCleanup {
public void executeMethod(){
for (Task[] badTypes : [select Id, Type from Task where Type=Null AND Subject LIKE '%Email%']) {
for(Task t : badTypes) {
t.type = 'Email';
}
update badTypes;
}
}
}

 

 

 

Message Edited by aalbert on 02-03-2009 03:11 PM
Message Edited by aalbert on 02-03-2009 03:11 PM
This was selected as the best answer
BarryPlumBarryPlum
Thanks aalbert.  I think that answers my questions. 
MargiroMargiro

Barry,

 

I was wondering if you had any success with this method of updating tasks. Did you use this controller for a visualforce page? If so, do you have an example of the code for it?

 

-Matt

BarryPlumBarryPlum

I don't remember if I used this method to clean up the existing tasks.  I may have ended up using Demand Tools for that.  I did implement a trigger to prevent it from being a problem again.  It was quite a while ago and early on when I was building triggers.  It may not be 'bulk safe' but I can post it if you're interested.