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
prady-cmprady-cm 

Apex batch class start method not running

 

I have apex  batch class

  

global class apexBatch implements Database.Batchable<sObject>{
 global final string query;
List<user>  lstUser= new List<user>();
Set<id>     setUserID= new Set<id>();



//constructor
global apexBatch () {
    if (system.Test.isRunningTest())
    {
        this.query='SELECT id FROM user limit 100';
    }
    else
    {
        this.query='SELECT id FROM user ;
    }
}


global Database.QueryLocator start(Database.BatchableContext BC) {

    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<sObject> scope) {

// do some processing


}

global void finish(Database.BatchableContext BC) {

}

 I am calling this class from test class using this code

 

 Test.startTest(); 
    apexBatch ba = new apexBatch();

    Database.executeBatch(ba);
      Test.stopTest();

 

When i check the code coverage i can only see that the constructor is covered, the start and execute methods are not covered at all.

Any idea what could cause this

Thanks

Navatar_DbSupNavatar_DbSup

Hi,

 

When I tried it give 90% coverage with the same code

 

Following test method I have used.

 

@isTest

private class TestClass

{

  public static testmethod void test()

  {

      Test.startTest();

      apexBatch ba = new apexBatch();

     Database.executeBatch(ba);

      Test.stopTest();

  }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

prady-cmprady-cm

This is really strange...

 

i am doing exactly the same..

Did it cover the start method or the execute method?

 

 

prady-cmprady-cm

My guess is that the 10 percent not covered are the start and executemethods

sri14sri14

I need apex batch class, for fetched query results put into .xls file and this .xls file needs to transfer via vf email templates.

Jason in ChinaJason in China

I am facing the same issue now. Still no any idea about this.