Things to Remember
Future methods are a great tool, but with great power comes great responsibility. Here are some things to keep in mind when using them:
-
Methods with the future annotation must be static methods, and can
only return a void type.
必须是静态方法,只能返回void -
The specified parameters must be primitive data types, arrays of
primitive data types, or collections of primitive data types; future
methods can’t take objects as arguments.
指定的参数必须是原始类型,原始类型的数组,原始类型的集合,
不能把objects作为参数 -
Future methods won’t necessarily execute in the same order they are
called. In addition, it’s possible that two future methods could run
concurrently, which could result in record locking if the two methods
were updating the same record.
future methods执行的顺序不一定是他们调用的顺序
也有可能两个 future methods同时执行,如果两个method修改同一条数据
,记录可能被锁 -
Future methods can’t be used in Visualforce controllers in
getMethodName(), setMethodName(), nor in the constructor.
不能被用在Visualforce controllers in
getMethodName(), setMethodName(), nor in the constructor. -
You can’t call a future method from a future method. Nor can you
invoke a trigger that calls a future method while running a future
method. See the link in the Resources for preventing recursive future
method calls. -
The getContent() and getContentAsPDF() methods can’t be used in
methods with the future annotation. -
You’re limited to 50 future calls per Apex invocation, and there’s an
additional limit on the number of calls in a 24-hour period. For more
information on limits, see the link below.