Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Apex Liberation : The evolution
of Flex Queue
Carolina Ruiz Medina
Principal Developer, Product Innovation team
cruiz@fina...
Carolina Ruiz Medina
Principal Developer, Product Innovation Team at
FinancialForce.com
cruiz@financialforce.com
@CarolEnL...
Stephen Willcock
Director, Product Innovation at FinancialForce.com
swillcock@financialforce.com
@stephenwillcock
foobarfo...
About
GREAT ALONE. BETTER TOGETHER.
• Native to Salesforce1™ Platform
since 2009
• Investors include Salesforce Ventures
•...
Heavy lifting
• Normal Execution limited by Apex
Governors
• Number of records to process
• CPU Time
• Heap Size
Working S...
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
W...
@future - show me the code!
public with sharing class FutureClass {
@future
static void myMethod(String a, Integer i) {
Sy...
We can track/monitor the batch jobs:
DataBase.executeBatch returns Id
We can only run 5 concurrent jobs
Batch Apex
We can ...
Batch Apex - show me the code!
public class UpdateAccountFields implements Database.Batchable<sObject>{
public final Strin...
Async Limits
Execution Governors
Batch start
Batch execute
Batch finish
@future
Queueable
250,000 method
calls in a 24 hou...
The Evolution… of Async Apex
The evolution of @future - Queueable
public class AsyncExecutionExample implements Queueable, Database.AllowsCallouts {
pu...
The evolution of @future - Queueable
public class AsyncExecutionExample implements Queueable, Database.AllowsCallouts {
pu...
The evolution of @future – Enhanced Futures (pilot)
@future (limits=2xHEAP)
public static void myMemoryHog() { }
@future (...
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 b...
Reordering Flex Queue items programmatically
Summer 15:
Boolean isSuccess = System.moveFlexQueueJob(jobId, positionNumber)...
Abort Flex Queue jobs and processing jobs in the same way:
system.abortJob(jobId);
The evolution of Batch Apex - Flex Queu...
• 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
pro...
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...
…. 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...
Recap
1. Having Several Async Processes
1. @future
2. Queueable
3. Batch Jobs
2. What to do now? Which one to use? Always ...
Thank you
Upcoming SlideShare
Loading in …5
×

Apex Liberation - the evolution of Flex Queue (DF15)

598 views

Published on

Using Batch Apex FlexQueue, the history of the feature and developer considerations in implementation.

Presented at Dreamforce 2015 by Carolina Ruiz Medina and Stephen Willcock

Links:

Speakers
https://twitter.com/carolenlanube
https://twitter.com/CodeCoffeeCloud
http://codeandvogue.com/
https://twitter.com/stephenwillcock
http://foobarforce.com/
http://www.financialforce.com/

Simple Batch Apex examples
https://github.com/stephenwillcock/apex-misc

Async Execution Governors
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm#non_transactional_gov_limits_section

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

BatchMan
https://twitter.com/innovativebrad

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Apex Liberation - the evolution of Flex Queue (DF15)

  1. 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. 2. Carolina Ruiz Medina Principal Developer, Product Innovation Team at FinancialForce.com cruiz@financialforce.com @CarolEnLaNube @CodeCoffeeCloud
  3. 3. Stephen Willcock Director, Product Innovation at FinancialForce.com swillcock@financialforce.com @stephenwillcock foobarforce.com
  4. 4. About GREAT ALONE. BETTER TOGETHER. • Native to Salesforce1™ Platform since 2009 • Investors include Salesforce Ventures • 650+ employees, San Francisco based 4
  5. 5. Heavy lifting • Normal Execution limited by Apex Governors • Number of records to process • CPU Time • Heap Size Working Synchronously
  6. 6. Making light work
  7. 7. Making light work Higher limits in Asynchronous • @future • Queueable • Batch • Pipeline (pilot)
  8. 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. 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. 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. 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. 12. Async Limits Execution Governors Batch start Batch execute Batch finish @future Queueable 250,000 method calls in a 24 hour period Scheduled
  13. 13. The Evolution… of Async Apex
  14. 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. 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. 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. 17. The evolution of Batch Apex…
  18. 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. 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. 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. 21. • Proof of Concept • Manage Flex Queue jobs • Lightning Components Introducing… BatchMan Brad Slater @innovativebrad
  22. 22. Demo
  23. 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. 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. 25. …. Rememeber, with a great power, comes great responsibility
  26. 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. 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!!
  28. 28. Thank you

×