0
votes
global class BatchClassForPDFGeneration implements Database.Batchable<sObject>{
public static string strFileDescription='codes';
private Order__c OrderDetails;
private List<ResponseWrapperData.orderItems> OrderLineItems;

public BatchClassForPDFGeneration(List<ResponseWrapperData.orderItems> OrderLineItems,Order__c OrderDetails){
    this.OrderLineItems=OrderLineItems;
    this.OrderDetails=OrderDetails;
}
global Database.QueryLocator start(Database.BatchableContext BC){
    String query = 'Select id from Order__c where id=\''+OrderDetails.id+'\' limit 1';
    return  Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC,List<sobject> scope) {     
}  
global void finish(Database.BatchableContext BC) {

    system.debug('Process End');
}}

Now calling this batch from apex class

  // call this method when voucher type is PDF
public static void createGiftCardPDF(ResponseWrapperData.Response ResponseObject,Order__c OrderDetails){

    // call batch class to generate pdf
    GC_BatchClassForPDFGeneration giftCardBatch=new GC_BatchClassForPDFGeneration(ResponseObject,OrderDetails);
    Database.executeBatch(giftCardBatch,200);
}

getting the following error

Constructor not defined: [BatchClassForPDFGeneration].(ResponseWrapperData.Response, Order__c)

1
18:17:29:433 FATAL_ERROR System.AsyncException: Database.executeBatch cannot be called from a batch start, batch executes, or future method. getting this error when performing an action in ecxecute - Edward

1 Answers

0
votes

You defined the constructor of your batch as BatchClassForPDFGeneration(List<ResponseWrapperData.orderItems> OrderLineItems,Order__c OrderDetails).

But you're calling it as

GC_BatchClassForPDFGeneration(ResponseWrapperData.Response ResponseObject,Order__c OrderDetails).

1st parameter is incompatible type so compiler complains. There's no constructor that takes the wrapper. Either add new one (it's OK to have mutliple constructors taking different arguments or no arguments at all) or change the parameter.

And batch can't be called from another batch (or more generally - another asynchronous operation). Do you have @future, Queueable, Schedulable or something like that that's calling createGiftCardPDF?