17

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 ?.

3 Answers 3

12

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.

22

While a @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.

1
  • This one is the best answer for me! @AdrianLarson would you mind updating the link, please? I need to see SF documentation on calling a queueable from within a future method so bad, but unfortunately, the link you've posted here doesn't take me there, Thanks!
    – Bahman.A
    Aug 31, 2020 at 21:29
0

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.

You must log in to answer this question.

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