Activity Forums Salesforce® Discussions Can we call a future method from a Salesforce batch class using Apex?

  • Aman

    Member
    April 23, 2018 at 11:11 am

    Hi ,

    we can't call future method from batch class. If you try to invoke a future method from Batch/Future you will get the below error -

    FATAL ERROR: Future method cant be called from future or Batch

  • Meddimala Ranjith

    Member
    April 23, 2018 at 11:15 am

    Thank u, Aman, What are the restriction of the future method?

  • PRANAV

    Member
    April 23, 2018 at 11:54 am

    Hi,

    A future method runs in the background, asynchronously. You can call a future method for executing long-running operations, such as callouts to external Web services or any operation you'd like to run in its own thread, on its own time.

    Yes, we can’t call future method from batch class.

    Some restriction of the future method are:

    • No more than 50 method {Methods with the future annotation} calls per Apex invocation
    • The maximum number of future method invocations per a 24-hour period is 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater. This limit is for your entire org and is shared with all asynchronous Apex: Batch Apex, Queueable Apex, scheduled Apex, and future methods.
    • Methods with the future annotation must be static methods
    • Can only return a void type
    • You can invoke future methods the same way you invoke any other method. However, a future method can’t invoke another future method
    • Methods with the future annotation cannot be used in Visualforce controllers in either getMethodName or setMethodName methods, nor in the constructor.
    • 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.
    • The getContent and getContentAsPDFPageReference methods cannot be used in methods with the future annotation

    For access to higher limits for future methods, and to invoke a future method from another future method, use the Future Methods with Higher Limits pilot.

    Hope this helps you more.

  • shariq

    Member
    September 20, 2018 at 6:48 pm

    Hi,

    NO we can't call async method from another async method, it will throw System.Async Exception.

    Hope this helps.

  • Aastha

    Member
    June 24, 2020 at 6:21 pm

    Hello Shariq,

    But we can call one batch class from another batch, finish() method.

    Thanks and Regards
    Aastha Jain

    • This reply was modified 4 years, 5 months ago by  Aastha.
  • manideep

    Member
    May 17, 2021 at 8:50 am

    Hi Aman,
    is there any work around to call future from batch class?

  • kishan

    Member
    May 17, 2021 at 10:53 am

    No, We cannot call future methods directly from batch apex but we can call a web service from batch class and that web service can call the @future method. Also, we can call the future method from finish method in the batch class.

Log In to reply.

Popular Salesforce Blogs