You need to sign in to do that
Don't have an account?
Kapil_Khandelwal
Future method cannot be called from a future or batch method: ExampleHelper.makeWebserviceCallout()
I want to schedule an apex class using System.schedule.
This is the class I need to schedule. (ExampleHelpera.pxc)
This is the class that implements schedulable and calls the apex class. (ScheduleTest.apxc)
Now I try Schedule the above code using following:
After running the above code snippet in Execute Anonymous Window, the schedule is being created (as I had verified it Setup > jobs > Scheduled jobs)
But the logic inside the apex class is not being executed.
I get the following error - Future method cannot be called from a future or batch method: ExampleHelper.makeWebserviceCallout()
But when I run my logic code in Execute Anonymous Window, it gets executed without any error.
Kindly help me out with the same.
Thanks in advance.
This is the class I need to schedule. (ExampleHelpera.pxc)
public class ExampleHelper { @future(callout=true) public static void makeWebserviceCallout(){ //logic goes here. } }
This is the class that implements schedulable and calls the apex class. (ScheduleTest.apxc)
public class ScheduleTest implements Schedulable, Database.AllowsCallouts, Database.Batchable<sObject> { public void execute(SchedulableContext SC) { Database.executebatch(new ScheduleTest()); } public Iterable<sObject> start(Database.Batchablecontext BC){ if( !System.isFuture()) { ExampleHelper.makeWebserviceCallout(); } return null; } public void execute(Database.BatchableContext BC, List<sObject> scope){ } public void finish(Database.BatchableContext info){ } }
Now I try Schedule the above code using following:
ScheduleTest st = new ScheduleTest(); String sch= '0 20 18 16 8 ?'; String jobId=System.schedule('Test Schedule', sch, st);
After running the above code snippet in Execute Anonymous Window, the schedule is being created (as I had verified it Setup > jobs > Scheduled jobs)
But the logic inside the apex class is not being executed.
I get the following error - Future method cannot be called from a future or batch method: ExampleHelper.makeWebserviceCallout()
But when I run my logic code in Execute Anonymous Window, it gets executed without any error.
Kindly help me out with the same.
Thanks in advance.
Batch CLass
I tried to implement it using Queueable, but now I am getting another error:
First error: Start did not return a valid iterable object.
1) http://amitsalesforce.blogspot.com/2017/08/webservice-callout-from-scheduled-apex.html
Let us know if this will help you