Question: I have 2000 batches to run in a single batch job. One of the batch gives "Attempt to de-reference a null object" error. I want to track this error. How can I track? I have used debug logs but they are pretty much in quantity. Is there any way to do so?

Answer: 
If you had debug logging enabled - just query the table that contains them:

```
select Id, Application, DurationMilliseconds, LastModifiedDate, Location, LogLength, LogUserId, Operation, Request, StartTime, Status, SystemModstamp 
from ApexLog
where status = 'Attempt to de-reference a null object'

```

(of course fine-tune the query to your user, time criteria etc as you see fit)

Then you can view the log by visiting link like that:
<https://cs7.salesforce.com/p/setup/layout/ApexDebugLogDetailEdit/d?setupid=ApexDebugLogs&apex_log_id=07LM0000008VWd3MAG>

(again - provide your own SF instance and log\_id)

---

**EDIT** (to answer the comment)

Yeah, I'm positive Status-based search can be the way to dig it out.

```
select Count(Id), Status
from ApexLog
group by status
order by Count(Id) DESC

```

![results from my prod. org.](https://i.stack.imgur.com/u0eAs.png)
Log all the error messages in a custom object .This is the best method i have heard so far.Keep the batch Id and record Id that failed and the error message in the custom object for each batch run.You can clean this for every month to avoid huge data in this .