You need to sign in to do that
Don't have an account?

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
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;
}
}
}
All Answers
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;
}
}
}
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
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.