1

I have created a schedule class with AllowCallouts interface used and invoking my batch Apex from It and also my Batch Apex has allowcallouts interface used. But still i am getting CalloutException. i am doing a callout in start method of batch apex and execution methods from re usable BAL helper class

Scheduler

global class KanbanizeCardActivitySchedule implements Schedulable, Database.AllowsCallouts {


global void execute(SchedulableContext sc) {

//small code blocks of getting 
//username,pswd,others from custom setting

//Inovoke of batch apex
        if(string.isNotBlank(userName) && string.isNotBlank(paswd) ){
            ID jobID = database.executeBatch(new KanabanizeCardActivityBatch(fieldsSet, wherClause, userName, paswd ), 200);
            system.debug('--jobID for Kanabanize Data Check--'+jobID);          
        }
}

Batch Apex

global class KanabanizeCardActivityBatch implements Database.Batchable<sobject>, Database.AllowsCallouts {



   global KanabanizeCardActivityBatch(set<String> qFields, String whClause, string kanbanUserName, string kanbanPswd){


     KanabanizeService_BAL.doLoginKanbanize(kanbanUserName, kanbanPswd);

       if(KanabanizeService_BAL.isStatusOkForLogin()){
         //setting some final variables here, based on response
       }

   }
  global Database.QueryLocator start(Database.BatchableContext BC){
      return Database.getQueryLocator(queryString);
   }

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

   //making a callout in execute method, some heavy lines cant share here
   }

  global void finish(){}

however when i call my batch apex outside scheduler pulling everything perfectly. Not sure this behaviour even after using allowcallouts interface. As per sf documentation we can call batch apex with allow callouts implemented.

2
  • @MartinLezer I already followed above approach, but still getting callout exception
    – SFDC_Igle
    Sep 6, 2017 at 7:14
  • I have one scheduler apex, one flow, and one apex to make integration, the scheduler calls the flow, and the flow calls the apex of integration, in this case, should give an error of "Callout from scheduled Apex not supported"? Sep 21, 2022 at 18:40

1 Answer 1

2

Resolved this , The root cause is invoking a webservice within Batch Apex constructor. It seems like database.AllowCallouts is only shows impact on execute method and start, finish methods of batch apex.

Not the answer you're looking for? Browse other questions tagged .