,

Future

Apex code supports annotations that influence the way code runs. An annotation is preceded by the ’@’ sign and is added right before the method that is affected by the annotation.

One particularly significant annotation is future. When you use this annotation, the following method is executed asynchronously. Asynchronous execution means that the method executes when the Force Platform has available resources. Control is immediately returned to the module calling the future method.

Methods with the future annotation have to be declared as static and must not return a value. For instance, the following is a valid declaration:

@future
Static void futureMethod() {
 code_block;
 }

The future annotation is ideal for use with web service callouts from Apex. You must add the (callout=true) modifier to the future annotation to use future methods for this purpose.

Another reason to use this annotation has to do with governor limits on data access, which you will learn about in the next chapter. Each method called with the future annotation is subject to its own governor limits. For instance, if you had a For loop that called a future method 10 times, each one of those invocations could retrieve the maximum number of records. If the method did not have a future annotation, all ten invocations would be subject to a single governor limit.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.4.174