Activity Forums Salesforce® Discussions What are the different things which we need to consider while using future methods in Salesforce?

  • Anjali

    Member
    August 22, 2018 at 5:06 am

    Hi Madhulika

    Different things which we need to consider while using future methods are-

    • Avoid adding large numbers of future methods to the asynchronous queue, if possible. If more than 2,000 unprocessed requests from a single organization are in the queue, any additional requests from the same organization will be delayed while the queue handles requests from other organizations.
    • Ensure that future methods execute as fast as possible. To ensure fast execution of batch jobs, minimize Web service callout times and tune queries used in your future methods. The longer the future method executes, the more likely other queued requests are delayed when there are a large number of requests in the queue.
    • Test your future methods at scale. Where possible, test using an environment that generates the maximum number of future methods you’d expect to handle. This will help determine if delays will occur.
    • Consider using batch Apex instead of future methods to process large numbers of records.
  • shradha jain

    Member
    August 22, 2018 at 5:06 am

    Hello Madhulika,

    The different things that need to  be consider while using future methods are:

    1. Methods with the future annotation cannot be used in Visualforce controllers in either getMethodName or setMethodName methods, nor in the constructor.
    2. 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.
    3. Future methods cannot be called from batch class.

    Thanks.

  • shariq

    Member
    September 17, 2018 at 10:48 pm

    Hi,

    Methods with the future annotation have the following limits:

    • No more than 50 method calls per Apex invocation

    Asynchronous calls, such as @future or executeBatch, called in a startTest, stopTest block, do not count against your limits for the number of queued jobs.

    • 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. To check how many asynchronous Apex executions are available, make a request to the REST API limits resource. See List Organization Limits in the REST API Developer Guide. The licenses that count toward this limit are full Salesforce user licenses or App Subscription user licenses. Chatter Free, Chatter customer users, Customer Portal User, and partner portal User licenses aren’t included.
      Future method jobs queued before a Salesforce service maintenance downtime remain in the queue. After service downtime ends and when system resources become available, the queued future method jobs are executed. If a future method was running when downtime occurred, the future method execution is rolled back and restarted after the service comes back up.
      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.

  • Parul

    Member
    September 21, 2018 at 1:41 pm

    hI

    To avoid adding large numbers of future methods to the asynchronous queue, if possible. If more than 2,000 unprocessed requests from a single organization are in the queue, any additional requests from the same organization will be delayed while the queue handles requests from other organizations.

    Future methods cannot call by batch class.

     

    Thanks

Log In to reply.

Popular Salesforce Blogs