I have a few batch jobs that are scheduled to run each morning, and I want to keep better track of all the actions they perform. I know I could find this via Debug logging, but when I turn it on it has the 20-event m limit and this makes it impractical for monitoring these jobs every day. Is there a way to create/view logs for every batch run?
I implemented Sean's advice below, but for some reason my code in the Batch logic is not creating records in my new Custom Object. Can anyone help me figure out what's wrong with my code? Here is the logic segment of the Batchable class:
global void execute(Database.BatchableContext BC, List<Lead> scope) {
List<Lead> toUpdate = new List<Lead>();
Batch_log__c myLog = new Batch_Log__c();
myLog.Batch_name__c = 'ChinaLeadReassignmentBatch';
String myLogText = '';
for (Lead l : scope){
if (l.OwnerID == '00570000001kTxHAAU'){
l.OwnerID = '00570000001jPVZAA2';
myLogText += string.valueOf(system.now()) + ': Lead ' + l.id + ' reassigned to Lingling. /n';
}
if (l.OwnerID == '00570000001jPVZAA2'){
l.OwnerID = '00570000001kTxHAAU';
myLogText += string.valueOf(system.now()) + ': Lead ' + l.id + ' reassigned to Jacky. /n';
}
toUpdate.add(l);
}
update toUpdate;
myLog.Log_text__c = myLogText;
insert myLog;
}
For context, the logic itself is supposed to find untouched leads more than 2 days old and reassign them to another sales rep.