Tracking errors in batch impossible as Dev Console stops logging or breaks with Server error

When single batch jobs fail only the last one is party shown in the Apex Logs page. This is not enough for debugging.

A better way ist to check the log entries that are written per batch execute.

The problem is: this does not work reliably as:

  1. Logs seem to be written only when you have an open Developer console
  2. The Developer console does not fail to reload due to strange “Server timeout errors”
  3. The Developer console doesn’t stop keep track of the new logs (sometimes it just stoppes without “Resume Updating” being available.

How can I guarantee that I have ALL the logs produced by a 10h batch available when I log in after it finished?

Answer

Another option could be to create a custom “error” object and then in your batch code you can use try / catch to trap errors and to write a row to the table. This lets you capture the error, the stack trace, plus you can add your own custom information such as what record was being processed at the time, which function you are in etc.

Attribution
Source : Link , Question Author : Robert Sösemann , Answer Author : Doug B

Leave a Comment