function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TheRealistTheRealist 

when and where will it be not possible to use @future methods?

Hi EveryOne,
Are there any certain things where we will not be allowed to use @Future methods such as test classes,schedulable classes or some complex triggers and any situations that will not allow us to use @future method?  
NagaNaga (Salesforce Developers) 
Hi TheRealist,

Below are the limitations of @future method:

Depending on the number of licenses you have you may bump into some org-wide limits as Salesforce imposes a limit on the number of future method invocations. You can only have 200 method calls per full Salesforce user license or Force.com App Subscription user license, per 24 hours. This is understandable (i.e., limits != evil) but what if you are doing data loading/cleanup or have installed a managed package that puts you over your limit, you simply have to wait for you invocations to reset and somehow reprocess those items that failed.

No more than 10 method calls per Apex invocation. This one is understandable as well but I've seen a number of projects where we've had to implement some other type of system (polling for instance) because the limitation makes this approach technically impossible. The example is, suppose you have a trigger that updates 11 contact records (or 200!) and needs to make a callout for each record. You are screwed unless you have the luxury of being able to rewrite your external webservice to accept a collection of records.

You cannot call a method annotated with @future from a method that also has the @future annotation. We've run into this a number of times as the class hierarchy grows in larger projects. You want to reuse an existing class but what happens if it already calls a @future method? Or what happens if an managed package contains a @future method?
The parameters for a @future method must be primitive data types, arrays of primitive data types, or collections of primitive data types. Not a big deal as you can typically pass the IDs of the affected records and query for them. But doesn't that seem like a waste of resources if the Apex that calls the @future method already holds these records? It would be great if you could pass a collection of sObject or Apex objects.
It's difficult to orchestrate processes with @future annotations because these methods do not necessarily execute in the same order they are called.
Unit tests are difficult to write. Period.

Best Regards
Naga Kiran
Nayana PawarNayana Pawar
Due to salesforce Limitation, you can't call a future method from inside a batch job and 
if you have a DML statement inside execute() method which triggers a call to future method it won't work 
because every run/instance of execute() method is a single transaction and so the trigger execution will
 be part of that single transaction.
Amit Chaudhary 8Amit Chaudhary 8
Hi TheRealist,

A future method runs in the background, asynchronously. You can call a future method for executing long-running operations, such ascallouts to external Web services or any operation you’d like to run in its own thread, on its own time. You can also make use of future methods to isolate DML operations on different sObject types to prevent the mixed DML error. Each future method is queued and executes when system resources become available. That way, the execution of your code doesn’t have to wait for the completion of a long-running operation. A benefit of using future methods is that some governor limits are higher, such as SOQL query limits and heap size limits
Please check below blog for more information
http://amitsalesforce.blogspot.in/2015/02/future-methods-in-salesforce.html

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


IMP:-
The reason why sObjects can’t be passed as arguments to future methods is because the sObject might change between the time you call the method and the time it executes. In this case, the future method will get the old sObject values and might overwrite them.  To work with sObjects that already exist in the database, pass the sObject ID instead (or collection of IDs) and use the ID to perform a query for the most up-to-date record. The following example shows how to do so with a list of IDs



Funtur Method limitation:-
1) You can't call a future method from inside a batch job and 
2) No more than 50 method calls per Apex invocation
3) 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

Please let us know if this will help u

Thanks
Amit Chaudhary
Mitch McConnellMitch McConnell
What is the expected behavior if one of the limits is reached?  Will it simply throw an Exception that the code can catch?