1

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.

1 Answer 1

0

I have created a new object that tracks bugs in my batches. Whenever an error occurs, it creates this new object. I put a time stamp on the object's title as well as which batch job it is coming from.

I then place more information that I need inside fields that I have created, for instance, I have created an error field where you can see what the error was. I have also created an id list field that shows all the ids that have failed in that batch job.

I'd imagine you could take this concept and apply it to your detailed log need.

3
  • Interesting idea. I've set up a "Batch log" custom object and have my batch logic write to a Long Text field on the object. My only concern is the 131,072 character limit. I have to say it is odd that one has to use such a hack to get basic functionality from Salesforce, but I guess it's what I've come to expect.
    – OBerm
    Commented Mar 20, 2015 at 13:01
  • You could always create multiple long text fields and write to a different field once the limit is reached. Commented Mar 20, 2015 at 15:26
  • I suppose may do that if it becomes a problem. More bandaids on a big pile of bandaids.
    – OBerm
    Commented Mar 20, 2015 at 15:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .