function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KMK91KMK91 

Test Data for AsyncApexJob

Hi Team,
Can you any help me on this i'm creating test data to cover the code for  AsyncApexJob Bactch class but it is not covering. 


public Database.QueryLocator start(Database.BatchableContext BC){ 
        string soqlQuery = 'Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email,'+ 
                                        'ExtendedStatus from AsyncApexJob where Status = \'Failed\'';
        /*
        AsyncApexJob jobInfo = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email, ExtendedStatus from AsyncApexJob where Status = : 'Failed' limit 1];                                      
        system.debug('AsyncApexJob:' + jobInfo) ; 
        */
                    
        if(test.isRunningTest()) {
            soqlQuery +=' limit 1';
            
        }
        return database.getQueryLocator(soqlQuery);                  
    
    }
Raj VakatiRaj Vakati
try this code ..set see all data true in case if you have't get any data 
 
@isTest
public TargetClassTest() {
    static testmethod void test() {
        test.startTest();
// YOUR batch here 
tets.stopTest();         


    }
}

 
KMK91KMK91
Hi Raj,
Thank you for Responding but i'm unable to cover this condition "where Status = \'Failed\'';"

Thanks
KMK