Activity Forums Salesforce® Discussions What is the use of “@future” annotation in Salesforce Apex Classes?

  • shariq

    Member
    September 22, 2018 at 10:53 am

    Future annotations are used to identify and execute methods asynchronously. If the method is annotated with “@future”, then it will be executed only when Salesforce has the available resources.

    For example, you can use it while making an asynchronous web service callout to an external service. Whereas without using the annotation, the web service callout is made from the same thread that is executing the Apex code, and no additional processing will occur until that callout is complete (synchronous processing).

  • Parul

    Member
    September 22, 2018 at 12:59 pm

    NOTE :-

    1) Methods with the future annotation must be static methods
    2) can only return a void type
    3) The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types
    4) Methods with the future annotation cannot take sObjects or objects as arguments.
    5) You can invoke future methods the same way you invoke any other method. However, a future method can’t invoke another future method
    6) No more than 50 method calls per Apex invocation
    7) 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
    8) 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
    9) To test methods defined with the future annotation, call the class containing the method in a startTest(), stopTest() code block. All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos