I don't know if I can't see the wood for the trees on this one, but I need some help.
- I have ~2,200,000 Accounts
- I have to update every one of them (some fairly complex logic involved)
- I have to do it overnight, in a 4 hour processing window
- The whole process takes ~10 hours
So, I set about implementing a 'self abort' in the execute method to prevent it processing for more than 4 hours, e.g.
if( System.NOW() > startTime.addMinutes( 240 ) )
{
// store lastProcessedId
CustomSetting__c settings = [select LastAccountProcessed__c From CustomSetting__c];
settings.LastAccountProcessed__c = lastProcessed;
update settings;
// abort
System.abortJob( BC.getJobId() );
return;
}
All good so far.
However, I can't think of a good way to mark the last processed account in order to start the process again the following night from the correct place. I did think about using Id and then adding :
Where Id > :lastProcessed
but you can only use the = operator with IDs. I would like to avoid adding a custom checkbox to the Account.
Has anyone done anything similar, if so what approach did you take?
Thanks!