SlideShare a Scribd company logo
Queueable Apex:
More Than an @future
Axaykumar Varu
Queueable Interface
• Take Control of your Asynchronous Apex processes by
using the Queueable interface.
• This interface enables you to add jobs to the queue and
monitor them, which is an enhanced way of running
your asynchronous Apex code compared to using future
methods.
• For Apex processes that run for a long time, you can
run them asynchronously by implementing the
Queueable interface and adding a job to the Apex job
queue.
• In this way, your asynchronous Apex job runs in the
background in its own thread and doesn’t delay the
execution of your main Apex logic.
Queueable Interface vs. @future
• Getting an ID for your job: When you submit your job
by invoking the System.enqueueJob method, the
method returns the ID of the new job. This ID
corresponds to the ID of the AsyncApexJob record
• Using non-primitive types: Your Queueable class can
contain member variables of non-primitive data types,
such as sObjects or custom Apex types. Those objects
can be accessed when the job executes.
• Chaining jobs: You can chain one job to another job by
starting a second job from a running job. Chaining jobs
is useful if you need to do some processing that
depends on another process to have run first.
Syntax
• After you submit your Queueable class for execution, the job is
added to the queue and will be processed when system resources
become available.
• You can monitor the status of your job programmatically by querying
AsyncApexJob or through the user interface in Setup by
clicking Jobs | Apex Jobs.
• To add this class as job on the queue
Testing Queueable Jobs
Chaining Jobs
• You can’t chain Queueable jobs in an Apex test. Doing so results in
an error.
• To avoid getting an error, you can check if Apex is running in test
context by calling Test.isRunningTest() before chaining jobs.
Queueable Apex Limits
• The execution of a queued job counts once against the
shared limit for Asynchronous Apex method executions.
• You can add up to 50 jobs to the queue with
System.enqueueJob in a single transaction.
• The maximum stack depth for chained jobs is
two(WI15), which means that you can link a job only
once and have a maximum of two jobs in the chain.
• No limit is enforced on the depth of chained jobs(SP15)
• One parent Job cannot have more than two child jobs.
Demo
• Business requirement: You have to send a callout to an
external service whenever a Case is closed.
• Constraints: The callout will be a REST POST method that
accepts a JSON body with all the non-null Case fields that are
filled exactly when the Case is closed.
• Using a future method, we will pass the case ID to the job
and so make a subsequent SOQL query: this is against the
requirement to pass the fields we have in the Case at the
exact time of the update.
• This might seem an excessive constraint, but with big ORGs
and hundreds of future methods in execution (due to system
overload), future methods can actually be executed after
minutes, so the Case state can be different from when the
future was actually fired.
Salesforce DUG - Queueable Apex
References
Queueable Apex
• https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/apex_queueing_jobs.htm
Future Method
• https://developer.salesforce.com/docs/atlas.en-
us.apexcode.meta/apexcode/apex_classes_annotation_
future.htm
Dev Blog: Queueable Apex: More Than an @future
• https://developer.salesforce.com/blogs/developer-
relations/2015/05/queueable-apex-future.html
• Inspect HTTP Request using: http://requestb.in/
Code for the Demo
• https://github.com/enreeco/apex-queueable-
interfaces-example
Questions?
Thank You!

More Related Content

What's hot (20)

PDF
Testing Angular
Lilia Sfaxi
 
PDF
All About PL/SQL Collections
Steven Feuerstein
 
PPTX
Building a REST Service in minutes with Spring Boot
Omri Spector
 
PDF
Choose your own adventure Chaos Engineering - QCon NYC 2017
Nora Jones
 
PPTX
Exception handling in java
ARAFAT ISLAM
 
PPTX
Delegetes in c#
Mahbub Hasan
 
PDF
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
PPTX
Xml and xml processor
Himanshu Soni
 
PPT
Postman.ppt
ParrotBAD
 
PDF
Regression Testing - An Overview
BugRaptors
 
PPTX
API Testing for everyone.pptx
Pricilla Bilavendran
 
PDF
Asynchronous Processing in Java/JEE/Spring
Naresh Chintalcheru
 
PPT
Performance testing jmeter
Bhojan Rajan
 
PDF
Confie no seu pipeline: Teste automaticamente um aplicativo Java de ponta a p...
Elias Nogueira
 
PPTX
Jdbc_ravi_2016
Ravinder Singh Karki
 
PDF
Operating System-Process Scheduling
Shipra Swati
 
PPT
Plsql
fika sweety
 
PPTX
Volume Testing
DivyaSure
 
PDF
API Testing following the Test Pyramid
Elias Nogueira
 
PDF
TDD vs. ATDD - What, Why, Which, When & Where
Daniel Davis
 
Testing Angular
Lilia Sfaxi
 
All About PL/SQL Collections
Steven Feuerstein
 
Building a REST Service in minutes with Spring Boot
Omri Spector
 
Choose your own adventure Chaos Engineering - QCon NYC 2017
Nora Jones
 
Exception handling in java
ARAFAT ISLAM
 
Delegetes in c#
Mahbub Hasan
 
Introduction to JPA and Hibernate including examples
ecosio GmbH
 
Xml and xml processor
Himanshu Soni
 
Postman.ppt
ParrotBAD
 
Regression Testing - An Overview
BugRaptors
 
API Testing for everyone.pptx
Pricilla Bilavendran
 
Asynchronous Processing in Java/JEE/Spring
Naresh Chintalcheru
 
Performance testing jmeter
Bhojan Rajan
 
Confie no seu pipeline: Teste automaticamente um aplicativo Java de ponta a p...
Elias Nogueira
 
Jdbc_ravi_2016
Ravinder Singh Karki
 
Operating System-Process Scheduling
Shipra Swati
 
Volume Testing
DivyaSure
 
API Testing following the Test Pyramid
Elias Nogueira
 
TDD vs. ATDD - What, Why, Which, When & Where
Daniel Davis
 

Similar to Salesforce DUG - Queueable Apex (20)

PPTX
Asynchronous Apex Salesforce World Tour Paris 2015
Samuel De Rycke
 
PDF
Build Reliable Asynchronous Code with Queueable Apex
Salesforce Developers
 
PPTX
Batch Apex in Salesforce
David Helgerson
 
PPTX
Episode 18 - Asynchronous Apex
Jitendra Zaa
 
PPTX
Apex Liberation - the evolution of Flex Queue (DF15)
Stephen Willcock
 
PDF
Apex Liberation: The Evolution of FlexQueues
Salesforce Developers
 
PPTX
Asynchronous Apex .pptx
KadharBashaJ
 
PPTX
Apex Flex Queue: Batch Apex Liberated
CarolEnLaNube
 
PPTX
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Jitendra Zaa
 
PDF
Advanced Apex Development - Asynchronous Processes
Salesforce Developers
 
PDF
Continuation_alan_20220503.pdf
Shen yifeng
 
PPT
Salesforce1 Platform for programmers
Salesforce Developers
 
PDF
Design Patterns for Asynchronous Apex
Salesforce Developers
 
PDF
Batch Jobs: Beyond the Basics
Salesforce Developers
 
PDF
Hyperbatch (LoteRapido) - Punta Dreamin' 2017
Daniel Peter
 
PPTX
Salesforce Summer 14 Release
Jyothylakshmy P.U
 
PDF
Technical Webinar: Patterns for Integrating Your Salesforce App with Off-Plat...
CodeScience
 
PPTX
Alternate for scheduled apex using flow builder
KadharBashaJ
 
PPTX
SFDC Introduction to Apex
Sujit Kumar
 
Asynchronous Apex Salesforce World Tour Paris 2015
Samuel De Rycke
 
Build Reliable Asynchronous Code with Queueable Apex
Salesforce Developers
 
Batch Apex in Salesforce
David Helgerson
 
Episode 18 - Asynchronous Apex
Jitendra Zaa
 
Apex Liberation - the evolution of Flex Queue (DF15)
Stephen Willcock
 
Apex Liberation: The Evolution of FlexQueues
Salesforce Developers
 
Asynchronous Apex .pptx
KadharBashaJ
 
Apex Flex Queue: Batch Apex Liberated
CarolEnLaNube
 
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Jitendra Zaa
 
Advanced Apex Development - Asynchronous Processes
Salesforce Developers
 
Continuation_alan_20220503.pdf
Shen yifeng
 
Salesforce1 Platform for programmers
Salesforce Developers
 
Design Patterns for Asynchronous Apex
Salesforce Developers
 
Batch Jobs: Beyond the Basics
Salesforce Developers
 
Hyperbatch (LoteRapido) - Punta Dreamin' 2017
Daniel Peter
 
Salesforce Summer 14 Release
Jyothylakshmy P.U
 
Technical Webinar: Patterns for Integrating Your Salesforce App with Off-Plat...
CodeScience
 
Alternate for scheduled apex using flow builder
KadharBashaJ
 
SFDC Introduction to Apex
Sujit Kumar
 
Ad

Recently uploaded (20)

PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Ad

Salesforce DUG - Queueable Apex

  • 1. Queueable Apex: More Than an @future Axaykumar Varu
  • 2. Queueable Interface • Take Control of your Asynchronous Apex processes by using the Queueable interface. • This interface enables you to add jobs to the queue and monitor them, which is an enhanced way of running your asynchronous Apex code compared to using future methods. • For Apex processes that run for a long time, you can run them asynchronously by implementing the Queueable interface and adding a job to the Apex job queue. • In this way, your asynchronous Apex job runs in the background in its own thread and doesn’t delay the execution of your main Apex logic.
  • 3. Queueable Interface vs. @future • Getting an ID for your job: When you submit your job by invoking the System.enqueueJob method, the method returns the ID of the new job. This ID corresponds to the ID of the AsyncApexJob record • Using non-primitive types: Your Queueable class can contain member variables of non-primitive data types, such as sObjects or custom Apex types. Those objects can be accessed when the job executes. • Chaining jobs: You can chain one job to another job by starting a second job from a running job. Chaining jobs is useful if you need to do some processing that depends on another process to have run first.
  • 4. Syntax • After you submit your Queueable class for execution, the job is added to the queue and will be processed when system resources become available. • You can monitor the status of your job programmatically by querying AsyncApexJob or through the user interface in Setup by clicking Jobs | Apex Jobs. • To add this class as job on the queue
  • 6. Chaining Jobs • You can’t chain Queueable jobs in an Apex test. Doing so results in an error. • To avoid getting an error, you can check if Apex is running in test context by calling Test.isRunningTest() before chaining jobs.
  • 7. Queueable Apex Limits • The execution of a queued job counts once against the shared limit for Asynchronous Apex method executions. • You can add up to 50 jobs to the queue with System.enqueueJob in a single transaction. • The maximum stack depth for chained jobs is two(WI15), which means that you can link a job only once and have a maximum of two jobs in the chain. • No limit is enforced on the depth of chained jobs(SP15) • One parent Job cannot have more than two child jobs.
  • 8. Demo • Business requirement: You have to send a callout to an external service whenever a Case is closed. • Constraints: The callout will be a REST POST method that accepts a JSON body with all the non-null Case fields that are filled exactly when the Case is closed. • Using a future method, we will pass the case ID to the job and so make a subsequent SOQL query: this is against the requirement to pass the fields we have in the Case at the exact time of the update. • This might seem an excessive constraint, but with big ORGs and hundreds of future methods in execution (due to system overload), future methods can actually be executed after minutes, so the Case state can be different from when the future was actually fired.
  • 10. References Queueable Apex • https://developer.salesforce.com/docs/atlas.en- us.apexcode.meta/apexcode/apex_queueing_jobs.htm Future Method • https://developer.salesforce.com/docs/atlas.en- us.apexcode.meta/apexcode/apex_classes_annotation_ future.htm Dev Blog: Queueable Apex: More Than an @future • https://developer.salesforce.com/blogs/developer- relations/2015/05/queueable-apex-future.html • Inspect HTTP Request using: http://requestb.in/ Code for the Demo • https://github.com/enreeco/apex-queueable- interfaces-example