[SalesForce] Where to find Batch job error logs

We have two batch jobs that run just after midnight. When I run it manually via the Developer Console Anonymous window, they run fine. But last night, the "Apex Jobs" window showed that they failed. The Status states:

 Completed  First error: Attempt to de-reference a null object

Now I know what that means, but I have no information to debug it. As I said, when I run it manually I can turn on the debug logs, but it does not fail.

It seems odd that there is no "master error log" where I can see more about what happened… or is there?

Best Answer

I'm afraid that you would need to have the Debug Logs running on the user who scheduled the actual batch job, as well as informative debug code (e.g. System.debug) within your Scheduled Apex class. If you to Setup | Monitor | Logs, you can add the user record which should be monitored. Resulting in different debug logs.

Note: only 20 logs can be created. So in case you have batch job scheduled during midnight, set up the user for logging right before leaving the office (hereby ensuring the user running the batch will not browser anymore and hereby not consume any of the 20 logs that can be created). Check again in the morning on the same place, you should be able to find back the logs from the batch.