Sonia Jaitely
Sonia Jaitely

Reputation: 1

in Salesforce I am calling apex Batch from APex class but it only calls the constructor of the batch and does not call start,execute and finish?

In Salesforce I am calling apex Batch from Apex class but it only calls the constructor of the batch and does not call start, execute and finish? What is going on?

I am calling the batch like this from a class.

ExportBatchClass  EXPBTCH = new ExportBatchClass();
Database.executeBatch(EXPBTCH);

and the batch is :

global class ExportBatchClass implements Database.Batchable < Sobject > , Database.Stateful {
    public String qryString;

    global ExportBatchClass(){}

    global ExportBatchClass(String qryString1){
        qryString=qryString1;
        System.debug('qryString======'+qryString);     
    }        //END ExportBatchClass //

    // Start Method
    global  Database.QueryLocator start(Database.BatchableContext BC){
      qryString='SELECT  Product__r.name From Products__c WHERE Name != null ORDER by Product__r.Name ASC';

      system.debug('########## in START  qryString = '+qryString);  
      return Database.getQueryLocator(qryString);
    }

  // Execute Logic
   global void  execute(Database.BatchableContext BC, List<Sobject> scope) {
        for(Sobject s : scope)  
        {
        Products__c pro=(Products__c)s;
        productRelateListBatch.add(pro);
        }   
        System.debug('productRelateListBatch======'+productRelateListBatch.size()); 
    }

   global void finish(Database.BatchableContext BC){

   }
}

What am I missing?

Upvotes: 0

Views: 1984

Answers (1)

Sonia Jaitely
Sonia Jaitely

Reputation: 1

Thank Q!! I resolved it.I just re-constructed it and the code now works fine.

Upvotes: 0

Related Questions