function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anu35anu35 

Why we cannot call Future method from batch class?

Future Methode and Batch class both are asynchronus but we can call batch class from batch class(In Finish Method) but not future from batch class why??
what is the reason?
Thanks
NagendraNagendra (Salesforce Developers) 
Hi Anu,

While @Future cannot be called from a batch class, a web service can. A web service can also call a @future method. So have your batch class call an apex web service that in turn calls your @future method.

There is one trick here. To call your web service from the batch class, you need a session Id. Don't call Userinfo.getsessionid from a scheduled batch class. You won't get a result. Instead, call Userinfo.getsessionId from your schedulable class and pass the id into your batch class as a parameter. Now you have everything you need to call @Future from a batch.

For more information please check with below links from the community. Hope this answers your question.

Please mark this post as solved if the information helps so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
anu35anu35
Thanks for you quick reply,
 This may be workaround, But I want to know the reason behind it . If the batch class and future method both are asynchronus process then why we cannot call future from batch.
Thanks,
Dinesh Chandra P SDinesh Chandra P S