Queueable Apex

Performing asynchronous logic within Salesforce

Presented by Scott Covert / @scottbcovert

Looking into the @future


global class MyFutureClass {

  @future 
  static void myMethod(String a, Integer i) {
    System.debug('Method called with: ' + a + ' and ' + i);
    // Perform long-running code
  }
}
						

Allows you to kick-off long-running processes asynchronously to prevent CPU timeout


  @future (callout=true)
  public static void doCalloutFromFuture() {
   //Add code to perform callout
}						

Limitations

  • @future methods cannot call @future methods (including via triggers)
  • Parameters can only be instances/collections of primitive types (no passing SObjects)
  • Unknown execution order

Workaround

Scheduler Ping Pong


* Slides taken from Dan Appleman's DF13 Session on Asynchronous Apex (Presentation) (Slides)

Queueable Apex

Limitations

  • Count against shared async method call limit
  • 50 jobs added to the queue within a single transaction
  • Only one job can be enqueued by queued apex

Schmimitations

Chaining

Source