I've created a scheduled Apex class to calculate the donor level (think 'gold', 'platinum', 'bronze', etc.) for a contact based on the amount donated. The class is fired by a trigger when new donations are added and also must be fired as payments older than one year are no longer applied toward the contact's donor level.
The trigger works great but the schedule does not.
Here's a screenshot of the the job stuck in the "queued" status:
And here's a screenshot of what the schedule looks like:
Finally here's the schedulable class:
global class DonorLevelSchedule implements Schedulable {
global void execute(SchedulableContext sc) {
list<Contact> contacts = new list<Contact>([select Id from Contact where Earliest_Eligible_Donation_Date__c < LAST_N_DAYS:365 ]);
set<Id> contactIds = new set<Id>();
for( contact c : contacts){
contactIds.add(c.Id);
}
if( contactIds!=null) DonorLevel.set(contactIds);
}
}
Any idea what's going on or how to fix this? Thanks in advance!
Best Answer
I can think of two things you can try:
Change the definition of your list (you are declaring a new List with the static SOQL in the constructor). While I'm not sure if that is a problem or not, I do know that normally, this would be written:
You will get more control over your schedule if you use the API to create a schedule. Try this: