SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.
SlideShare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.
Successfully reported this slideshow.
Activate your 14 day free trial to unlock unlimited reading.
Apex Liberation - the evolution of Flex Queue (DF15)
Enhanced Futures blog post
mailto:https://developer.salesforce.com/blogs/engineering/2014/06/bigger-apex-limits-enhanced-futures.html#https://developer.salesforce.com/blogs/engineering/2014/06/bigger-apex-limits-enhanced-futures.html
Winter 16 Release Notes - FlexQueue Class
http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_apex_flexqueue_class.htm
Winter 16 Release Notes - New Methods
http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_apex_new_classes_methods.htm
Enhanced Futures blog post
mailto:https://developer.salesforce.com/blogs/engineering/2014/06/bigger-apex-limits-enhanced-futures.html#https://developer.salesforce.com/blogs/engineering/2014/06/bigger-apex-limits-enhanced-futures.html
Winter 16 Release Notes - FlexQueue Class
http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_apex_flexqueue_class.htm
Winter 16 Release Notes - New Methods
http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_apex_new_classes_methods.htm
Apex Liberation - the evolution of Flex Queue (DF15)
1.
Apex Liberation : The evolution
of Flex Queue
Carolina Ruiz Medina
Principal Developer, Product Innovation team
cruiz@financialforce.com
@CarolEnLaNube
@CodeCoffeeCloud
Stephen Willcock
Director, Product Innovation
swillcock@financialforce.com
@stephenwillcock
2.
Carolina Ruiz Medina
Principal Developer, Product Innovation Team at
FinancialForce.com
cruiz@financialforce.com
@CarolEnLaNube
@CodeCoffeeCloud
3.
Stephen Willcock
Director, Product Innovation at FinancialForce.com
swillcock@financialforce.com
@stephenwillcock
foobarforce.com
4.
About
GREAT ALONE. BETTER TOGETHER.
• Native to Salesforce1™ Platform
since 2009
• Investors include Salesforce Ventures
• 650+ employees, San Francisco based
4
5.
Heavy lifting
• Normal Execution limited by Apex
Governors
• Number of records to process
• CPU Time
• Heap Size
Working Synchronously
7.
Making light work
Higher limits in Asynchronous
• @future
• Queueable
• Batch
• Pipeline (pilot)
8.
Execute when there are
available resources
@future
Process a higher
number of records
Increased Governor
Limits in Async
We don’t have job id for @future jobs
as @future does not return anything
The method does not necessarily execute in
the same order is called
We can’t monitor @future jobs
Parameters must be primitive data types
9.
@future - show me the code!
public with sharing class FutureClass {
@future
static void myMethod(String a, Integer i) {
System.debug(’Primitive variable' + a + ' and ' + i+’But I run ASYNCHROUNOUSLY');
// ALL THE LOGIC HERE
}
}
10.
We can track/monitor the batch jobs:
DataBase.executeBatch returns Id
We can only run 5 concurrent jobs
Batch Apex
We can chain batch jobs
Possibility to use iterator and process
different objects (or none)
We cannot reorder or set priorities
Process up to 50M records
11.
Batch Apex - show me the code!
public class UpdateAccountFields implements Database.Batchable<sObject>{
public final String Query; public final String Entity;
public final String Field; public final String Value;
public UpdateAccountFields(String q, String e, String f, String v){
Query=q; Entity=e; Field=f;Value=v;
}
public Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC,
List<sObject> scope){
for(Sobject s : scope){s.put(Field,Value);
} update scope;
}
public void finish(Database.BatchableContext BC){
}
}
Simple Batch Apex Examples
12.
Async Limits
Execution Governors
Batch start
Batch execute
Batch finish
@future
Queueable
250,000 method
calls in a 24 hour
period
Scheduled
14.
The evolution of @future - Queueable
public class AsyncExecutionExample implements Queueable, Database.AllowsCallouts {
public void execute(QueueableContext context) {
Account a = new Account(Name='Acme',Phone='(415) 555-1212');
insert a;
}
}
ID jobID = System.enqueueJob(new AsyncExecutionExample());
AsyncApexJob jobInfo = [SELECT Status,NumberOfErrors FROM AsyncApexJob WHERE
Id=:jobID];
15.
The evolution of @future - Queueable
public class AsyncExecutionExample implements Queueable, Database.AllowsCallouts {
public void execute(QueueableContext context) {
Account a = new Account(Name='Acme',Phone='(415) 555-1212');
insert a;
}
}
ID jobID = System.enqueueJob(new AsyncExecutionExample());
AsyncApexJob jobInfo = [SELECT Status,NumberOfErrors FROM AsyncApexJob WHERE
Id=:jobID];
Supported but
undocumented
16.
The evolution of @future – Enhanced Futures (pilot)
@future (limits=2xHEAP)
public static void myMemoryHog() { }
@future (limits=3xCPU)
public static void myIntenseLogicalProcessing() { }
Blogged June 2014: Bigger Apex Limits with Enhanced Futures
23.
The further evolution of Batch Apex
Spring 15
Flex Queue
introduced
95 Batch Apex jobs
in the Flex Queue
waiting to be
processed + 5
concurrent Batch
Apex processes
Reorder Flex Queue
items via a Flex
Queue UI
Summer 15
Reorder Flex Queue
items
programmatically
(pilot)
Winter 16
Reorder Flex Queue
items
programmatically
GA
???
Programmatically
determine current
Flex Queue order
Queueable jobs in
Flex Queue
24.
What can Flex Queue
Do for us?
1. Queue up to 100 jobs rather than killing any more than 5
2. Batch Apex no longer limited to admins – if you build an App for your users
3. We can implement our own prioritization mechanism
25.
…. Rememeber, with a great power, comes great responsibility
26.
…. Remember, with great power, comes great responsibility
1. Consider the effect of new job status value on existing Batch management
code
2. Consider the possibility of jobs never being processed
3. Processes may be dependent on one another - strategy for chaining jobs in
the Flex Queue
4. Multiple processes managing the Flex Queue (currently no ability to read the
current order)
27.
Recap
1. Having Several Async Processes
1. @future
2. Queueable
3. Batch Jobs
2. What to do now? Which one to use? Always batch?
1. You should use the one that better fits to your necessity …. The power is now
in your hands!!