Collectively referred to as asynchronous code batchable, queueable, and the @future
methods contract a tradeoff with the Salesforce1 platform. In exchange for running the code asynchronously, meaning we have no control over when it's actually executed, the platform relaxes certain governor limitations. For instance, during normal, synchronous Apex execution, you are limited to modifying 10,000 records per DML call. Attempting to access more than 10,000 records throws a SOQL error. However, during the execution of a batchable class, those governor limits are reset every time the execute method is called.
Conceptually, asynchronous code executes in two steps. First, the code is queued. As system resources allow, the system pulls jobs off the queue and executes them. As usual, the devil is in the details. Batchable, Queueable, and the @future
annotation all have various tradeoffs that distinguish them from each other. Knowing when to use which one is crucial. As we work...