+ All Categories
Home > Technology > Design Patterns for Asynchronous Apex

Design Patterns for Asynchronous Apex

Date post: 23-Jan-2015
Category:
Upload: salesforce-developers
View: 696 times
Download: 7 times
Share this document with a friend
Description:
Have you ever wanted to schedule an Apex operation to repeat every 10 minutes? To have one future call start another one? Is the 10 future call per context limit getting you down? Recent additions to the Apex language have opened the door to entirely new asynchronous design patterns. Join us to learn about the recent language changes, how they are used, and the kinds of design patterns they enable.
14
Design Patterns for Asynchronous Apex Dan Appleman, Full Circle CRM, CTO Author: Advanced Apex Programming for Salesforce.com and Force.com @danappleman
Transcript
Page 1: Design Patterns for Asynchronous Apex

Design Patterns for Asynchronous Apex

Dan Appleman, Full Circle CRM, CTOAuthor: Advanced Apex Programming for Salesforce.com and Force.com@danappleman

Page 2: Design Patterns for Asynchronous Apex

Safe harborSafe 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.

Page 3: Design Patterns for Asynchronous Apex

Our goal today…

Explore how recent changes in Apex support new solutions to common asynchronous “challenges”

Page 4: Design Patterns for Asynchronous Apex

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

Page 5: Design Patterns for Asynchronous Apex

What would you like to do?▪Future calling future▪Chaining asynchronous operations▪More frequent and finer resolution scheduled jobs▪Anything else?

Page 6: Design Patterns for Asynchronous Apex

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

Page 7: Design Patterns for Asynchronous Apex

Challenge: Scheduled Apex blocks updatesSolution: Use type system to dynamically create classes that implement delegated functionality

Scheduled Class Delegated ClassDynamic creation

Platform

Page 8: Design Patterns for Asynchronous Apex

Challenge: Perform a series of batch operationsSolution: Chain batch operations

Start Execute Execute FinishCode

Other batch

Page 9: Design Patterns for Asynchronous Apex

Challenge: Future call can’t call a future callSolution: Alternate future calls with scheduled Apex

Future Scheduled Future

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

Page 10: Design Patterns for Asynchronous Apex

Challenge: Create more than 10 future calls in an execution context

Solution: Replace future calls with custom async request objectUse scheduled Apex or scheduled batch to process requests

Insertobjects

Scheduled Batch

“Future”

“Future”

“Future”

Page 11: Design Patterns for Asynchronous Apex

For more informationAdvanced 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

Page 12: Design Patterns for Asynchronous Apex

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

Page 13: Design Patterns for Asynchronous Apex

Download sample code for this session atwww.AdvancedApex.com/Dreamforce13

Page 14: Design Patterns for Asynchronous Apex

Recommended