Activity Forums Salesforce Questions and Answers Can we call a future method from a Salesforce batch class using Apex?

  • Can we call a future method from a Salesforce batch class using Apex?

  • Meddimala Ranjith

    Member
    April 23, 2018 at 10:58 am

    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.

Viewing 1 - 5 of 5 posts

Log in to reply.

Original Post
0 of 0 posts June 2018
Now