+ Start a Discussion

AsyncApexJob object doesn't contain history records

We have scheduled batch classes implemented and monitoring them at the 'Apex Jobs' page in the setup. However it seems it's showing only very recent records and when try to retrieve from 'AsyncApexJob' object there also having only the recent records.

Is there anyway that we can retrieve old records of this table?
v varaprasadv varaprasad
Hi Madhu,

Batch jobs and debug log will contain maximum last 24 hours data only.

Use Database.stateful in class and add all results to list string.In finish method, you can insert data to object.
You can create one custom object : 

Add batch apex success or failure records into that custom object.

Sample code : 
global class CopyLoginHistory implements Database.Batchable<LoginHistory> {

    global CopyLoginHistory(){}

    global List<LoginHistory> start(Database.BatchableContext BC) {
    	return [Select <fields> From LoginHistory Where //condition to prevent dupe records.. may be by time frame?];

    global void execute(Database.BatchableContext BC, List<LoginHistory> scope) {
       List<LoginHistory__c> lhList = new List<LoginHistory__c>();
       for(LoginHistory lh : scope){
               new LoginHistory__c(
       insert lhList;

    global void finish(Database.BatchableContext BC) {}

Hope this helps you.

@For Support : varaprasad4sfdc@gmail.com