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

PPTX
Salesforce asynchronous apex
PDF
Build Reliable Asynchronous Code with Queueable Apex
PPTX
Batchable vs @future vs Queueable
PPTX
Batch Apex in Salesforce
PPTX
Triggers and order of execution1
PPTX
Episode 19 - Asynchronous Apex - Batch apex & schedulers
PPTX
Salesforce Basic Development
PPT
Salesforce REST API
Salesforce asynchronous apex
Build Reliable Asynchronous Code with Queueable Apex
Batchable vs @future vs Queueable
Batch Apex in Salesforce
Triggers and order of execution1
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Salesforce Basic Development
Salesforce REST API

What's hot (20)

PDF
Manage Salesforce Like a Pro with Governance
PDF
Lwc presentation
PPTX
Salesforce Integration Patterns
PPTX
Salesforce Development Best Practices
PDF
Best Practices for Rolling Out New Functionality
PDF
Introduction to Apex Triggers
PDF
Introduction to the Salesforce Security Model
PPTX
Asynchronous Apex Salesforce World Tour Paris 2015
PDF
C# simplified
PPT
Mule salesforce integration solutions
PPTX
Demystify Salesforce Bulk API
PDF
All About Test Class in #Salesforce
PDF
1Z0-997.pdf
PDF
Apex Testing Best Practices
PPTX
Admin Webinar—An Admin's Guide to Profiles & Permissions
PDF
FDMEE script examples
PDF
Trialforce
PPTX
Large Data Volume Salesforce experiences
PPT
Automating security test using Selenium and OWASP ZAP - Practical DevSecOps
Manage Salesforce Like a Pro with Governance
Lwc presentation
Salesforce Integration Patterns
Salesforce Development Best Practices
Best Practices for Rolling Out New Functionality
Introduction to Apex Triggers
Introduction to the Salesforce Security Model
Asynchronous Apex Salesforce World Tour Paris 2015
C# simplified
Mule salesforce integration solutions
Demystify Salesforce Bulk API
All About Test Class in #Salesforce
1Z0-997.pdf
Apex Testing Best Practices
Admin Webinar—An Admin's Guide to Profiles & Permissions
FDMEE script examples
Trialforce
Large Data Volume Salesforce experiences
Automating security test using Selenium and OWASP ZAP - Practical DevSecOps
Ad

Similar to Salesforce DUG - Queueable Apex (20)

PPTX
SFDC Batch Apex
PDF
OHHttpStubs
PPTX
Distributed Model Validation with Epsilon
PPTX
Training – Going Async
PPTX
Parallel Programming
ODP
Nexthink Library - replacing a ruby on rails application with Scala and Spray
PPTX
Coding For Cores - C# Way
PPTX
Java Colombo: Developing Highly Scalable Apps
DOCX
Assg 11 Priority Queues and Queue ApplicationsCOSC 2336 S.docx
PPTX
New AWS Services for Bioinformatics
PPTX
Unit Testing
PDF
Nyc big datagenomics-pizarroa-sept2017
PPT
Web Programming using Asynchronous JavaX
PPTX
Task parallel library presentation
PDF
.NET Fest 2018. Владимир Крамар. Многопоточное и асинхронное программирование...
PDF
EUC2015 - Load testing XMPP servers with Plain Old Erlang
PPTX
Asynchronous programming in ASP.NET
PPTX
Episode 18 - Asynchronous Apex
PDF
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
PPTX
TDD Training
SFDC Batch Apex
OHHttpStubs
Distributed Model Validation with Epsilon
Training – Going Async
Parallel Programming
Nexthink Library - replacing a ruby on rails application with Scala and Spray
Coding For Cores - C# Way
Java Colombo: Developing Highly Scalable Apps
Assg 11 Priority Queues and Queue ApplicationsCOSC 2336 S.docx
New AWS Services for Bioinformatics
Unit Testing
Nyc big datagenomics-pizarroa-sept2017
Web Programming using Asynchronous JavaX
Task parallel library presentation
.NET Fest 2018. Владимир Крамар. Многопоточное и асинхронное программирование...
EUC2015 - Load testing XMPP servers with Plain Old Erlang
Asynchronous programming in ASP.NET
Episode 18 - Asynchronous Apex
[AWS Dev Day] 실습워크샵 | Amazon EKS 핸즈온 워크샵
TDD Training
Ad

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Electronic commerce courselecture one. Pdf
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
MIND Revenue Release Quarter 2 2025 Press Release
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
NewMind AI Weekly Chronicles - August'25 Week I
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

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