18

i have created a schedulable class which has to trigger a batch job. The run method for the batch class will get list of data to process from a webservice callout. Now, i got the exception below. Any suggestions please.

System.CalloutException: Callout from scheduled Apex not supported.

global class scheduledDeltaBatchable implements Schedulable {
   global void execute(SchedulableContext sc) {
    ID batchprocessid = BatchUpsertSAPCustomerMasterBPSync.run(SAPServices.GetSAPCustomerMasterBPSync('Delta'));
   }
}

1 Answer 1

22

If you want to do it in the schedule class you will need to do it in an @future method:

https://developer.salesforce.com/blogs/developer-relations/2010/02/spring-10-saw-the-general-availability-of-one-of-my-favorite-new-features-of-the-platform-the-apex-schedulerwith-the-apex-s.html

or here on stack exchange:

Scheduled Apex, Callouts and Running a Batch

Why not just perform the callout in your Batch Apex start method? This means you will always start the Batch Apex job from your Scheduled apex job, but i think is on balance better than having to marshall schedule jobs between @future jobs?

if you want to do it within the batch that is ran by the schedule you will need to implement the callout interface

global class scheduledDeltaBatchable implements Schedulable, Database.AllowsCallouts

To use a callout in batch Apex, specify Database.AllowsCallouts in the class definition

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm

1
  • 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"? Commented Sep 21, 2022 at 18:38

You must log in to answer this question.

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