You need to sign in to do that
Don't have an account?
Callout from scheduled Apex not supported errors
Hi All,
I am calling a batch class (with Database.AllowsCallouts) from a Scheduler class. The batch class is making http callouts. Both classes are using Apex version 27.0.
global class MyScheduler implements Schedulable {
global void execute(SchedulableContext sc) {
String query = 'Select .....';
MyBatchClass batchApex = new MyBatchClass(query);
ID bpid = Database.executeBatch(batchApex);
}
}
In my developer environment, the above code is working just fine. However when I deploy it to production (as part of a managed package) and run the scheduled class, I am getting the error:
"Callout from scheduled Apex not supported"
Why it works without issues in dev but not in production? Do I need to do anything in the production environment to get it working?
I have also tried the following variation of the scheduler class:
global class MyScheduler implements Schedulable {
global void execute(SchedulableContext sc) {
runBatchProgram();
}
@future (callout=true)
static void runBatchProgram() {
String query = 'Select .....';
MyBatchClass batchApex = new MyBatchClass(query);
ID bpid = Database.executeBatch(batchApex);
}
}
With this I get the error: Database.executeBatch cannot be called from a batch or future method.
Any help is appreciated as I am stuck.
Madhav
Hi All,
I am able to figure the solution. I moved a callout that was initially in the batch class contructor to the start method and this fixed the issue. Not sure why it worked in the dev environment initially. My guess why it works now is that "Database.AllowCallouts" comes into play after the batch class is constructed and works for start(), executeBatch(), and probably finish() methods.
Kind Regards
Madhav
All Answers
2. You can't call and future method from batch or batch from a future as both are async request.
Hi Bhawani,
Thank you for your reply. Yes, I am using Database.Callouts on the batch class - which makes it possible to call the batch class from a scheduler class.
Like I mentioned in the initial email, this is working in my DE but now in production. Any other ideas??
Thanks in advance
Correction:
I meant this is working in my DE but not in production.
What error you are getting in Production?
Hi Bhawani,
Yes I have done so. I see the following error in the developer console when the scheduled class is run:
Callout from scheduled Apex not supported.
The batch class in question looks as follows:
Hi All,
I am able to figure the solution. I moved a callout that was initially in the batch class contructor to the start method and this fixed the issue. Not sure why it worked in the dev environment initially. My guess why it works now is that "Database.AllowCallouts" comes into play after the batch class is constructed and works for start(), executeBatch(), and probably finish() methods.
Kind Regards
Madhav
I am facing this same issue, have you overcome on it? if yes then please share solution with me.
Regards
Sumit