I have two future methods f1 & f2.
Each of them takes long time to process as such I have annotated them as @future.
There is a scenario in which I need to make a callout to f2 from f1.
Any workarounds to achieve this ?.
You cannot call another future method from a future method. As per Salesforce documentation,
You cannot call a method annotated with future from a method that also has the future annotation. Nor can you call a trigger from an annotated method that calls another annotated method.
If you do not have dependency between f1 & f2, you can call both methods one by one from original class.
@future method cannot call another, it can execute a
Queueable. Here is some documentation. They might even be more useful than
@future methods for both operations, as they can be chained.
You cannot normally call a future method in another future method, but if your salesforce license has the pilot feature enabled then you can call a future method from another future method.
To get the pilot feature you ll need to contact the salesforce where you can also double or triple some governor limits of asynchronous apex in your org.
For more information, see Future Methods with Higher Limits.
Basically, not many salesforce orgs has this feature availale and is not needed much, but if you're asked this question in any interview you can get the info from above link.