SlideShare a Scribd company logo
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
Carolina Ruiz Medina
Principal Developer, Product Innovation Team at
FinancialForce.com
cruiz@financialforce.com
@CarolEnLaNube
@CodeCoffeeCloud
Stephen Willcock
Director, Product Innovation at FinancialForce.com
swillcock@financialforce.com
@stephenwillcock
foobarforce.com
About
GREAT ALONE. BETTER TOGETHER.
• Native to Salesforce1™ Platform
since 2009
• Investors include Salesforce Ventures
• 650+ employees, San Francisco based
4
Heavy lifting
• Normal Execution limited by Apex
Governors
• Number of records to process
• CPU Time
• Heap Size
Working Synchronously
Making light work
Making light work
Higher limits in Asynchronous
• @future
• Queueable
• Batch
• Pipeline (pilot)
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
@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
}
}
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
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
Async Limits
Execution Governors
Batch start
Batch execute
Batch finish
@future
Queueable
250,000 method
calls in a 24 hour
period
Scheduled
The Evolution… of Async Apex
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];
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
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
The evolution of Batch Apex…
The evolution of Batch Apex - Flex Queue
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
Reordering Flex Queue items programmatically
Summer 15:
Boolean isSuccess = System.moveFlexQueueJob(jobId, positionNumber);
Winter 16:
Boolean isSuccess = FlexQueue.moveBeforeJob(jobToMoveId, jobInQueueId);
Boolean isSuccess = FlexQueue.moveAfterJob(jobToMoveId, jobInQueueId);
Boolean isSuccess = FlexQueue.moveJobToEnd(jobId);
Boolean isSuccess = FlexQueue.moveJobToFront(jobId);
The evolution of Batch Apex - Flex Queue
Show me the code!
Release Notes:
FlexQueue Class
New Methods
Abort Flex Queue jobs and processing jobs in the same way:
system.abortJob(jobId);
The evolution of Batch Apex - Flex Queue
Show me the code!
• Proof of Concept
• Manage Flex Queue jobs
• Lightning Components
Introducing…
BatchMan
Brad Slater
@innovativebrad
Demo
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
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
…. Rememeber, with a great power, comes great responsibility
…. 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)
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!!
Thank you

More Related Content

PDF
Apex Liberation: The Evolution of FlexQueues
PDF
Moving from app services to azure functions
PDF
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
PPTX
Deploying Machine Learning in production without servers - #serverlessCPH
PDF
Serverless authentication
PDF
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...
PDF
New Relic .NET Agent Overview
PPTX
Continuous Delivery using AWS CodePipeline, AWS Lambda & AWS ElasticBeanstalk
Apex Liberation: The Evolution of FlexQueues
Moving from app services to azure functions
Intro to Airflow: Goodbye Cron, Welcome scheduled workflow management
Deploying Machine Learning in production without servers - #serverlessCPH
Serverless authentication
Flink Forward Berlin 2018: Wei-Che (Tony) Wei - "Lessons learned from Migrati...
New Relic .NET Agent Overview
Continuous Delivery using AWS CodePipeline, AWS Lambda & AWS ElasticBeanstalk

What's hot (19)

PDF
Plaλ!
PPTX
What's new in c# 8.0
PPT
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
PDF
2019-05-16 aOS Luxembourg - 6 - Flow avancé - Serge Luca
PDF
Graphs: Fabric of DevOps
PDF
Continuous Delivery in the Cloud with Bitbucket Pipelines
PPTX
State in stateless serverless functions
PPTX
Provisioning SPFx Solutions to SharePoint Online using PnP, ALM APIs and more!
PDF
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...
PPTX
Fast parallel data loading with the bulk API
PDF
DevOps with Serverless
PPTX
Automating it management with Puppet + ServiceNow
PPTX
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
PDF
Presentation tim numann
PPTX
Azure Durable Functions
PPTX
Modern software testing and processes 2019
PDF
JCConf 2016 - Dataflow Workshop Labs
PDF
James Baxley - Statically typing your GraphQL app
PPTX
Into the cloud
Plaλ!
What's new in c# 8.0
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
2019-05-16 aOS Luxembourg - 6 - Flow avancé - Serge Luca
Graphs: Fabric of DevOps
Continuous Delivery in the Cloud with Bitbucket Pipelines
State in stateless serverless functions
Provisioning SPFx Solutions to SharePoint Online using PnP, ALM APIs and more!
Flink Forward Berlin 2018: Lasse Nedergaard - "Our successful journey with Fl...
Fast parallel data loading with the bulk API
DevOps with Serverless
Automating it management with Puppet + ServiceNow
C# Async on iOS and Android - Miguel de Icaza, CTO of Xamarin
Presentation tim numann
Azure Durable Functions
Modern software testing and processes 2019
JCConf 2016 - Dataflow Workshop Labs
James Baxley - Statically typing your GraphQL app
Into the cloud
Ad

Similar to Apex Liberation - the evolution of Flex Queue (DF15) (20)

PPTX
SFDC Batch Apex
PPTX
Salesforce asynchronous apex
PPTX
Batch Apex in Salesforce
PPTX
Apex Flex Queue: Batch Apex Liberated
PPTX
Episode 19 - Asynchronous Apex - Batch apex & schedulers
PPTX
Asynchronous Apex Salesforce World Tour Paris 2015
PDF
Hyperbatch (LoteRapido) - Punta Dreamin' 2017
PPTX
Asynchronous Apex .pptx
PPTX
Salesforce DUG - Queueable Apex
PPTX
Salesforce Apex Hours :- Hyper batch
PPTX
Batchable vs @future vs Queueable
PPTX
Salesforce Summer 14 Release
PDF
Batch Jobs: Beyond the Basics
PDF
Advanced Apex Development - Asynchronous Processes
PPTX
Episode 18 - Asynchronous Apex
PDF
Salesforce Asynchronous Apex using Batch Apex QR Solutions.pdf
PDF
Design & Develop Batch Applications in Java/JEE
PDF
HyperBatch
PDF
Hyperbatch danielpeter-161117095610
SFDC Batch Apex
Salesforce asynchronous apex
Batch Apex in Salesforce
Apex Flex Queue: Batch Apex Liberated
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Asynchronous Apex Salesforce World Tour Paris 2015
Hyperbatch (LoteRapido) - Punta Dreamin' 2017
Asynchronous Apex .pptx
Salesforce DUG - Queueable Apex
Salesforce Apex Hours :- Hyper batch
Batchable vs @future vs Queueable
Salesforce Summer 14 Release
Batch Jobs: Beyond the Basics
Advanced Apex Development - Asynchronous Processes
Episode 18 - Asynchronous Apex
Salesforce Asynchronous Apex using Batch Apex QR Solutions.pdf
Design & Develop Batch Applications in Java/JEE
HyperBatch
Hyperbatch danielpeter-161117095610
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PPTX
Spectroscopy.pptx food analysis technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Empathic Computing: Creating Shared Understanding
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development
Spectroscopy.pptx food analysis technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
Digital-Transformation-Roadmap-for-Companies.pptx
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
MYSQL Presentation for SQL database connectivity
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Programs and apps: productivity, graphics, security and other tools
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Empathic Computing: Creating Shared Understanding
NewMind AI Weekly Chronicles - August'25 Week I
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

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
  • 13. The Evolution… of Async Apex
  • 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
  • 17. The evolution of Batch Apex…
  • 18. The evolution of Batch Apex - Flex Queue 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
  • 19. Reordering Flex Queue items programmatically Summer 15: Boolean isSuccess = System.moveFlexQueueJob(jobId, positionNumber); Winter 16: Boolean isSuccess = FlexQueue.moveBeforeJob(jobToMoveId, jobInQueueId); Boolean isSuccess = FlexQueue.moveAfterJob(jobToMoveId, jobInQueueId); Boolean isSuccess = FlexQueue.moveJobToEnd(jobId); Boolean isSuccess = FlexQueue.moveJobToFront(jobId); The evolution of Batch Apex - Flex Queue Show me the code! Release Notes: FlexQueue Class New Methods
  • 20. Abort Flex Queue jobs and processing jobs in the same way: system.abortJob(jobId); The evolution of Batch Apex - Flex Queue Show me the code!
  • 21. • Proof of Concept • Manage Flex Queue jobs • Lightning Components Introducing… BatchMan Brad Slater @innovativebrad
  • 22. Demo
  • 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!!