Down and Dirty with Async Apex | Salesforce Developers Blog

I just came out of an Apex deep dive session at Dreamforce where the code was flying thick and the discussions focused on the new Force.com for Amazon Web Services toolkit, Dynamic Apex and Async Apex. I couldn’t help but think back to much of the discussions from this mornings keynote which focused on convergent clouds and the power of combining services and functionality from the major players in the cloud computing space. It seems that many of the new technical introductions so far have focused around enabling this confluence.

One of these core enablers, the new @future annotation in the Winter ’09 release, provides the ability to enable callouts from triggers and other locations. (something that will definitely come in handy using the new Force.com for Facebook toolkit announced this morning!) Previously when making a callout to say, an external web service, all processing would wait until the response was received but now this is not the case. Now with the @future annotation and callout set to true, the request will be added to an execution queue and you can continue processing with no delay.

Below is a simple example of creating a Asynchronous Callout:


@future (callout=true)
public static void doMyFutureCallout()
{
//add code here
}

As is often the case, there are some factors to consider when using the @future annotation, perhaps the most important is that the async methods may not be executed in the order you expect and parameters must only be of primitive datatypes.

If Asynchronous callouts are something you are interested in check out the online docs for more information.

Stay up to date with the latest news from the Salesforce Developers Blog

Subscribe