SlideShare a Scribd company logo
Design Patterns for Asynchronous Apex
Dan Appleman, Full Circle CRM, CTO
Author: Advanced Apex Programming for Salesforce.com and Force.com
@danappleman
Safe harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties
materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results
expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be
deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other
financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any
statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new
functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our
operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any
litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our
relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our
service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to
larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is
included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent
fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor
Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently
available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions
based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these
forward-looking statements.
Our goal today…
Explore how recent changes in Apex support new solutions to
common asynchronous “challenges”
Quick review
▪Why do we use asynchronous code?
▪The big three: Future calls, Batch Apex and Scheduled Apex
▪The Rules
▪ Future can’t call future, 10 future calls per context
▪ Batch can’t call future, only 5 at once
▪ Limited # of scheduled Apex jobs
▪ Scheduled Apex job blocks updates
What would you like to do?
▪Future calling future
▪Chaining asynchronous operations
▪More frequent and finer resolution scheduled jobs
▪Anything else?
What’s new?
▪Spring 12:

New type system

▪Winter 13:

Start batch in the Finish statement of a batch

▪Summer 13: Increased # of Scheduled Apex job
Scheduled batch
▪Winter 14:

CronJobDetail object
Challenge: Scheduled Apex blocks updates
Solution: Use type system to dynamically create classes that
implement delegated functionality

Platform

Scheduled Class

Dynamic
creation

Delegated Class
Challenge: Perform a series of batch operations
Solution: Chain batch operations

Code
Start

Execute

Execute

Finish

Other batch
Challenge: Future call can’t call a future call
Solution: Alternate future calls with scheduled Apex

Future

Scheduled

This design pattern is problematic:
•Can burn through limits
•Potential concurrency issues

Future
Challenge: Create more than 10 future calls in an
execution context
Solution: Replace future calls with custom async request object
Use scheduled Apex or scheduled batch to process requests
Insert
objects

Scheduled

Batch

“Future”
“Future”
“Future”
For more information
Advanced Apex Programming for Salesforce.com and Force.com –
Second Edition
•
•
•
•
•

Incorporates changes through Winter 14
Designing for CPU Time limits
Extended chapter on triggers
Extended chapter on asynchronous patterns
New chapter on concurrency patterns
All about Full Circle CRM
Full Circle CRM develops native Salesforce.com applications
that enable marketers to accurately track and measure
marketing campaign performance directly in Salesforce
▪ Bridge the information gap between leads and contacts
▪ Obtain complete and detailed campaign performance metrics
▪ Develop advanced campaign attribution and influence analytics

Booth 1324 Moscone North
Download sample code for this session at
www.AdvancedApex.com/Dreamforce13
Design Patterns for Asynchronous Apex

More Related Content

What's hot (20)

PDF
Apex Enterprise Patterns: Building Strong Foundations
Salesforce Developers
 
PPTX
Salesforce Integration Pattern Overview
Dhanik Sahni
 
PPT
Apex Trigger Debugging: Solving the Hard Problems
Salesforce Developers
 
PDF
Advanced Apex Development - Asynchronous Processes
Salesforce Developers
 
PPTX
Apache NiFi in the Hadoop Ecosystem
DataWorks Summit/Hadoop Summit
 
PPTX
Salesforce sales cloud solutions
JanBask LLC
 
PPTX
Integrating with salesforce
Mark Adcock
 
PDF
All About Test Class in #Salesforce
Amit Singh
 
PPTX
REST API in Salesforce
Vivek Deepak
 
PDF
15 Tips on Salesforce Data Migration - Naveen Gabrani & Jonathan Osgood
Salesforce Admins
 
PPTX
Salesforce Integration Patterns
usolutions
 
PPTX
Oracle Fusion Architecture
Vinay Kumar
 
PDF
Introduction to Apex Triggers
Salesforce Developers
 
PDF
Best practices for fusion hcm cloud implementation
mohamed refaei
 
PDF
Data Migration Steps PowerPoint Presentation Slides
SlideTeam
 
PPTX
OAuth with Salesforce - Demystified
Calvin Noronha
 
PPTX
Introduction to Salesforce Connected Apps
Cloud Analogy
 
PDF
Nagios, Getting Started.
Hitesh Bhatia
 
PPTX
Episode 20 - Trigger Frameworks in Salesforce
Jitendra Zaa
 
PDF
Improving Presto performance with Alluxio at TikTok
Alluxio, Inc.
 
Apex Enterprise Patterns: Building Strong Foundations
Salesforce Developers
 
Salesforce Integration Pattern Overview
Dhanik Sahni
 
Apex Trigger Debugging: Solving the Hard Problems
Salesforce Developers
 
Advanced Apex Development - Asynchronous Processes
Salesforce Developers
 
Apache NiFi in the Hadoop Ecosystem
DataWorks Summit/Hadoop Summit
 
Salesforce sales cloud solutions
JanBask LLC
 
Integrating with salesforce
Mark Adcock
 
All About Test Class in #Salesforce
Amit Singh
 
REST API in Salesforce
Vivek Deepak
 
15 Tips on Salesforce Data Migration - Naveen Gabrani & Jonathan Osgood
Salesforce Admins
 
Salesforce Integration Patterns
usolutions
 
Oracle Fusion Architecture
Vinay Kumar
 
Introduction to Apex Triggers
Salesforce Developers
 
Best practices for fusion hcm cloud implementation
mohamed refaei
 
Data Migration Steps PowerPoint Presentation Slides
SlideTeam
 
OAuth with Salesforce - Demystified
Calvin Noronha
 
Introduction to Salesforce Connected Apps
Cloud Analogy
 
Nagios, Getting Started.
Hitesh Bhatia
 
Episode 20 - Trigger Frameworks in Salesforce
Jitendra Zaa
 
Improving Presto performance with Alluxio at TikTok
Alluxio, Inc.
 

Viewers also liked (18)

PPTX
Batchable vs @future vs Queueable
Boris Bachovski
 
PDF
Apex Design Patterns
Salesforce Developers
 
PPTX
Salesforce Apex Ten Commandments
NetStronghold
 
PDF
Follow the evidence: Troubleshooting Performance Issues
Salesforce Developers
 
PPTX
Apex Flex Queue: Batch Apex Liberated
CarolEnLaNube
 
PDF
Build Reliable Asynchronous Code with Queueable Apex
Salesforce Developers
 
PDF
Apex Nirvana
Salesforce Developers
 
PPTX
Spring '16 release belgium salesforce user group samuel de rycke
Samuel De Rycke
 
PPTX
Batch Apex in Salesforce
David Helgerson
 
PPTX
Building strong foundations apex enterprise patterns
andyinthecloud
 
PPTX
Salesforce APIs
Samuel De Rycke
 
PPTX
Salesforce World Tour 2016 : Lightning Out : Components on any Platform
andyinthecloud
 
PPTX
Integrate with External Systems using Apex Callouts
Salesforce Developers
 
PPTX
Dive Deep into Apex: Advanced Apex!
Salesforce Developers
 
PPTX
Salesforce1 API Overview
Samuel De Rycke
 
PPTX
Salesforce Process builder Vs Workflows
Prasanna Deshpande ☁
 
PDF
Apex Design Patterns
Salesforce Developers
 
PPTX
Governor limits
Shivanath Devinarayanan
 
Batchable vs @future vs Queueable
Boris Bachovski
 
Apex Design Patterns
Salesforce Developers
 
Salesforce Apex Ten Commandments
NetStronghold
 
Follow the evidence: Troubleshooting Performance Issues
Salesforce Developers
 
Apex Flex Queue: Batch Apex Liberated
CarolEnLaNube
 
Build Reliable Asynchronous Code with Queueable Apex
Salesforce Developers
 
Apex Nirvana
Salesforce Developers
 
Spring '16 release belgium salesforce user group samuel de rycke
Samuel De Rycke
 
Batch Apex in Salesforce
David Helgerson
 
Building strong foundations apex enterprise patterns
andyinthecloud
 
Salesforce APIs
Samuel De Rycke
 
Salesforce World Tour 2016 : Lightning Out : Components on any Platform
andyinthecloud
 
Integrate with External Systems using Apex Callouts
Salesforce Developers
 
Dive Deep into Apex: Advanced Apex!
Salesforce Developers
 
Salesforce1 API Overview
Samuel De Rycke
 
Salesforce Process builder Vs Workflows
Prasanna Deshpande ☁
 
Apex Design Patterns
Salesforce Developers
 
Governor limits
Shivanath Devinarayanan
 
Ad

Similar to Design Patterns for Asynchronous Apex (20)

PPTX
Force.com Friday : Intro to Apex
Salesforce Developers
 
PDF
Shorten Your Development Time with an Extensible Design for Apex
Salesforce Developers
 
PPTX
Elevate Madrid Essentials - Advance Track
CarolEnLaNube
 
PDF
Just-In-Time Sharing Using Apex
Salesforce Developers
 
PDF
Bulkify Your Org
Salesforce Developers
 
PPTX
Intro to Apex - Salesforce Force Friday Webinar
Abhinav Gupta
 
PPTX
CCT London 2013 Theatre Intro to Apex
Peter Chittum
 
PDF
Force.com Friday: Intro to Force.com
Salesforce Developers
 
PPTX
Salesforce Campus Tour - Developer Intro
James Ward
 
PPT
Dreamforce 2009: Behind-the-Scenes at Salesforce.com: Delivering 3 Major Rele...
Steve Greene
 
PPTX
Salesforce Campus Tour - Declarative
James Ward
 
PPTX
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Salesforce Developers
 
PDF
Enterprise Integration - Solution Patterns From the Field
Salesforce Developers
 
PDF
Design Patterns: ISV Recipes for Success (Dreamforce 2015)
Salesforce Partners
 
PDF
How To Staff for Salesforce Innovation
Bluewolf
 
PPTX
Architecting in the Cloud: Choosing the Right Technologies for your Solution
Jeff Douglas
 
PDF
Integrating High-Velocity External Data in Your Salesforce Application
Salesforce Developers
 
PPTX
Deliver Innovations Faster
Salesforce Engineering
 
PPTX
Salesforce Bilbao Elevate '15 - 1st developer workshop
northspainsalesforcedevelopergroup
 
PPT
Using Node.js for Mocking Apex Web Services
Jeff Douglas
 
Force.com Friday : Intro to Apex
Salesforce Developers
 
Shorten Your Development Time with an Extensible Design for Apex
Salesforce Developers
 
Elevate Madrid Essentials - Advance Track
CarolEnLaNube
 
Just-In-Time Sharing Using Apex
Salesforce Developers
 
Bulkify Your Org
Salesforce Developers
 
Intro to Apex - Salesforce Force Friday Webinar
Abhinav Gupta
 
CCT London 2013 Theatre Intro to Apex
Peter Chittum
 
Force.com Friday: Intro to Force.com
Salesforce Developers
 
Salesforce Campus Tour - Developer Intro
James Ward
 
Dreamforce 2009: Behind-the-Scenes at Salesforce.com: Delivering 3 Major Rele...
Steve Greene
 
Salesforce Campus Tour - Declarative
James Ward
 
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Salesforce Developers
 
Enterprise Integration - Solution Patterns From the Field
Salesforce Developers
 
Design Patterns: ISV Recipes for Success (Dreamforce 2015)
Salesforce Partners
 
How To Staff for Salesforce Innovation
Bluewolf
 
Architecting in the Cloud: Choosing the Right Technologies for your Solution
Jeff Douglas
 
Integrating High-Velocity External Data in Your Salesforce Application
Salesforce Developers
 
Deliver Innovations Faster
Salesforce Engineering
 
Salesforce Bilbao Elevate '15 - 1st developer workshop
northspainsalesforcedevelopergroup
 
Using Node.js for Mocking Apex Web Services
Jeff Douglas
 
Ad

More from Salesforce Developers (20)

PDF
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Salesforce Developers
 
PDF
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Salesforce Developers
 
PDF
Local development with Open Source Base Components
Salesforce Developers
 
PPTX
TrailheaDX India : Developer Highlights
Salesforce Developers
 
PDF
Why developers shouldn’t miss TrailheaDX India
Salesforce Developers
 
PPTX
CodeLive: Build Lightning Web Components faster with Local Development
Salesforce Developers
 
PPTX
CodeLive: Converting Aura Components to Lightning Web Components
Salesforce Developers
 
PPTX
Enterprise-grade UI with open source Lightning Web Components
Salesforce Developers
 
PPTX
TrailheaDX and Summer '19: Developer Highlights
Salesforce Developers
 
PDF
Live coding with LWC
Salesforce Developers
 
PDF
Lightning web components - Episode 4 : Security and Testing
Salesforce Developers
 
PDF
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
PDF
Lightning web components episode 2- work with salesforce data
Salesforce Developers
 
PDF
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
PDF
Migrating CPQ to Advanced Calculator and JSQCP
Salesforce Developers
 
PDF
Scale with Large Data Volumes and Big Objects in Salesforce
Salesforce Developers
 
PDF
Replicate Salesforce Data in Real Time with Change Data Capture
Salesforce Developers
 
PDF
Modern Development with Salesforce DX
Salesforce Developers
 
PDF
Get Into Lightning Flow Development
Salesforce Developers
 
PDF
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 
Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Salesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Salesforce Developers
 
Local development with Open Source Base Components
Salesforce Developers
 
TrailheaDX India : Developer Highlights
Salesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Salesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
Salesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
Salesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Salesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
Salesforce Developers
 
Live coding with LWC
Salesforce Developers
 
Lightning web components - Episode 4 : Security and Testing
Salesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
Salesforce Developers
 
Lightning web components episode 2- work with salesforce data
Salesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Salesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Salesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Salesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Salesforce Developers
 
Modern Development with Salesforce DX
Salesforce Developers
 
Get Into Lightning Flow Development
Salesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Salesforce Developers
 

Recently uploaded (20)

PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Python basic programing language for automation
DanialHabibi2
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
July Patch Tuesday
Ivanti
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 

Design Patterns for Asynchronous Apex

  • 1. Design Patterns for Asynchronous Apex Dan Appleman, Full Circle CRM, CTO Author: Advanced Apex Programming for Salesforce.com and Force.com @danappleman
  • 2. Safe harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
  • 3. Our goal today… Explore how recent changes in Apex support new solutions to common asynchronous “challenges”
  • 4. Quick review ▪Why do we use asynchronous code? ▪The big three: Future calls, Batch Apex and Scheduled Apex ▪The Rules ▪ Future can’t call future, 10 future calls per context ▪ Batch can’t call future, only 5 at once ▪ Limited # of scheduled Apex jobs ▪ Scheduled Apex job blocks updates
  • 5. What would you like to do? ▪Future calling future ▪Chaining asynchronous operations ▪More frequent and finer resolution scheduled jobs ▪Anything else?
  • 6. What’s new? ▪Spring 12: New type system ▪Winter 13: Start batch in the Finish statement of a batch ▪Summer 13: Increased # of Scheduled Apex job Scheduled batch ▪Winter 14: CronJobDetail object
  • 7. Challenge: Scheduled Apex blocks updates Solution: Use type system to dynamically create classes that implement delegated functionality Platform Scheduled Class Dynamic creation Delegated Class
  • 8. Challenge: Perform a series of batch operations Solution: Chain batch operations Code Start Execute Execute Finish Other batch
  • 9. Challenge: Future call can’t call a future call Solution: Alternate future calls with scheduled Apex Future Scheduled This design pattern is problematic: •Can burn through limits •Potential concurrency issues Future
  • 10. Challenge: Create more than 10 future calls in an execution context Solution: Replace future calls with custom async request object Use scheduled Apex or scheduled batch to process requests Insert objects Scheduled Batch “Future” “Future” “Future”
  • 11. For more information Advanced Apex Programming for Salesforce.com and Force.com – Second Edition • • • • • Incorporates changes through Winter 14 Designing for CPU Time limits Extended chapter on triggers Extended chapter on asynchronous patterns New chapter on concurrency patterns
  • 12. All about Full Circle CRM Full Circle CRM develops native Salesforce.com applications that enable marketers to accurately track and measure marketing campaign performance directly in Salesforce ▪ Bridge the information gap between leads and contacts ▪ Obtain complete and detailed campaign performance metrics ▪ Develop advanced campaign attribution and influence analytics Booth 1324 Moscone North
  • 13. Download sample code for this session at www.AdvancedApex.com/Dreamforce13