SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Asynchronous Apex
Paris June 25, 2015
Samuel De Rycke
Salesforce MVP
ABSI
@SamuelDeRycke
Samuel Moyson
Developer
ABSI
@SamuelMoyson
Speakers
#DevZone #SalesforceWorldTour #AsyncApex
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 intellectual property and other
litigation, risks associated with 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-Q for the
most recent fiscal quarter ended July 31, 2012. This 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.
Follow Developer Force for the Latest News
@SalesforceDevs – #SalesforceDevs
Developer Force – Force.com Community
+Developer Force – Force.com Community
Developer Force
Developer Force Group
Synchronous vs Asynchronous
• Synchronous
• Asynchronous
Process 1
Process 2
Waiting for response
Process 1
Process 2
Continues working
Get response
• Synchronous
•Immediate and fast actions
•Enforce single, serial, transactions
•Normal governor limits
• Asynchronous
•Actions that should not block the rest of the process
•Processes where duration is of lesser concern
•Higher governor limits
Synchronous vs Asynchronous
Types of Asynchronous Apex
• Batch Apex
• Future Methods
• Queueable
• Scheduled
• Continuation
Batch Apex
Use when you want to:
• Process a big “batch” of records in smaller “batches” of records
• Each smaller batch is handled in a discrete transaction
• Monitor queue of batch jobs
• Batchable context with information about batch
Batch Apex
Start
Execute
Finish
global Database.QueryLocator start(Database.BatchableContext BC) {
//Query for data
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope) {
//Do some actions with data
//DML Statement
}
global void finish(Database.BatchableContext BC) {
//Give some feedback about statistics of batch
//Do post batch actions
}
Batch Apex
Process up to 50 million records
Monitor batch progress in the Setup User Interface
Admins can reorder batch priority with Apex Flex Queue
Maximum 5 concurrent batches processed (status Queued)
Not always easy to debug
Future Methods
Use when you want to:
• Execute methods that should not delay or respond to the
current Apex transaction
• Isolate transaction contexts and DML contexts
• Make asynchronous call outs to Web services
Pilot: Future methods with Higher Limits
• Set specific governor limits for a specific method x2 or x3
Future Methods
Executepublic class MyClass
{
public void myNormalMethod{
List<ID> recordIds;
//Synchronous logic here
myFutureMethod(recordIds);
// More synchronous logic
}
@future
public static void myFutureMethod(List<ID> recordIds)
{
// Get those records based on the IDs
// Process records
}
}
@future
Future Methods
Executed near instantly
Bypass mixed DML limitations
Pilot: increase limits for specific methods
Maximum 50 future methods per Apex invocation
Only accepts (collections of) primitive data types
Future methods can not invoke other future methods
Can not be invoked from Visualforce Constructors, Get & Set
Queueable Apex
Use when you want to:
• Start long-running operations and monitor them within the
current process or the user interface
• Pass complex types
• Chain asynchronous jobs
Queueable Apex
implements
Queueable
ID jobID = System.enqueueJob(new MyQueueableJob ());
public class MyQueueableJob implements Queueable {
//Other logic
public void execute(QueueableContext context) {
//Asynchronous logic here
//Optionally: enqueue another job
}
}
Queueable Apex
Executed near instantly
Unlimited depth of chained jobs (except for Dev & Trial orgs)
Use sObject and Apex objects as parameters
Maximum 50 jobs queued in a single apex transaction
When chaining jobs only 1 ‘child job’ is supported
Jobs can not be chained in test context.
Chained jobs do not support callouts (Winter ‘16 ?)
Schedulable Apex
Use when you want to:
• Schedule Apex classes
• Specify schedule with User Interface or Apex
Schedulable Apex
// Schedulable class
global class MySchedulable implements Schedulable {
global void execute(SchedulableContext sc) {
// Execute apex
}
}
// Schedule from Apex:
MySchedulable schApex = new MySchedulable ();
String sch = '0 15 10 * * ?';
String jobID = System.schedule('MySchedulable', sch, schApex);
implements
Schedulable
Schedulable Apex
Schedule from UI
Schedulable Apex
Execute Apex on scheduled intervals
Admins can manage the schedule from the Setup UI
Maximum 100 scheduled jobs at the same time
Using the Setup User Interface the minimum interval is 1 hour
Synchronous web service callouts are not supported
Continuation
Use when you want to:
–Make callouts from Visualforce pages
–Special one: synchronous asynchronous
Twitter demo
https://github.com/SamuelMoy/TwitterContinuationDemo
Continuation
Visualforce Continuation Webservice
startRequest
processResponse
Class
● Objects
● Methods
Continuation
// Visualforce page
<apex:page showHeader="true" sidebar="true" controller="TwitterController">
<apex:form >
<!-- Invokes the action method when the user clicks this button. -->
<apex:commandButton action="{!startRequest}" value="Start"
reRender="result"/>
</apex:form>
<!-- This output text component displays the callout response body. -->
<apex:outputText id="result" value="{!status} " />
</apex:page>
Visualforce
Continuation
// Action method
public Object startRequest() {
// Create continuation with a timeout
Continuation con = new Continuation(40);
// Set callback method
con.continuationMethod='processResponse';
HttpRequest req = new HttpRequest();
// Add callout request to continuation
this.requestLabel = con.addHttpRequest(req);
// Return the continuation
return con;
}
startRequest
Continuation
// Callback method
public Object processResponse() {
// Get the response by using the unique label
HttpResponse response = Continuation.getResponse(this.requestLabel);
// Set the result variable that is displayed on the Visualforce page
this.result = response.getBody();
// Return null to re-render the original Visualforce page
return null;
}
processResponse
Continuation
Integrate Visualforce with back-end systems
No long-running concurrent request limit for call outs
that last longer than 5 seconds
Visualforce page suspended until action completed
(= Synchronous)
Maximum 3 asynchronous callouts in one single Continuation
Maximum timeout continuation is 120 seconds
Testing Asynchronous Apex
• Invoke asynchronous Apex between the Test.startTest() and
Test.stopTest() methods.
• The Test.stopTest() method will execute all asynchronous and
scheduled Apex synchronously.
• Assert :-)
Recap
Batch Future Schedulable Queueable Continuation
High volume
of records
Near instantly
Primitive
parameters
Schedule jobs Chain jobs
Complex
parameters
Callouts in
Visualforce
Samuel De Rycke
Salesforce MVP
ABSI
@SamuelDeRycke
Samuel Moyson
Developer
ABSI
@SamuelMoyson
Q & A
developer.salesforce.com/trailhead
La communauté des développeurs Salesforce en France
Rejoignez la communauté de développeurs en France et venez partager votre expérience
sur la plateforme Salesforce1
bit.ly/dugParis
bit.ly/dugStQuentin
bit.ly/dugSuisse
bit.ly/dugBelgique
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Build Reliable Asynchronous Code with Queueable Apex
Build Reliable Asynchronous Code with Queueable ApexBuild Reliable Asynchronous Code with Queueable Apex
Build Reliable Asynchronous Code with Queueable Apex
 
Getting Started With Apex REST Services
Getting Started With Apex REST ServicesGetting Started With Apex REST Services
Getting Started With Apex REST Services
 
Lwc presentation
Lwc presentationLwc presentation
Lwc presentation
 
Introduction to Apex for Developers
Introduction to Apex for DevelopersIntroduction to Apex for Developers
Introduction to Apex for Developers
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
 
Salesforce Integration
Salesforce IntegrationSalesforce Integration
Salesforce Integration
 
Understanding the Salesforce Architecture: How We Do the Magic We Do
Understanding the Salesforce Architecture: How We Do the Magic We DoUnderstanding the Salesforce Architecture: How We Do the Magic We Do
Understanding the Salesforce Architecture: How We Do the Magic We Do
 
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulersEpisode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulers
 
Admin Webinar—An Admin's Guide to Profiles & Permissions
Admin Webinar—An Admin's Guide to Profiles & PermissionsAdmin Webinar—An Admin's Guide to Profiles & Permissions
Admin Webinar—An Admin's Guide to Profiles & Permissions
 
Introduction to lightning Web Component
Introduction to lightning Web ComponentIntroduction to lightning Web Component
Introduction to lightning Web Component
 
Asynchronous apex
Asynchronous apexAsynchronous apex
Asynchronous apex
 
5 Secret Weapons Of A Great Salesforce Architect
5 Secret Weapons Of A Great Salesforce Architect5 Secret Weapons Of A Great Salesforce Architect
5 Secret Weapons Of A Great Salesforce Architect
 
SFDC Batch Apex
SFDC Batch ApexSFDC Batch Apex
SFDC Batch Apex
 
Process builder vs Triggers
Process builder vs TriggersProcess builder vs Triggers
Process builder vs Triggers
 
Lightning Data Service: Eliminate Your Need to Load Records Through Controllers
Lightning Data Service: Eliminate Your Need to Load Records Through ControllersLightning Data Service: Eliminate Your Need to Load Records Through Controllers
Lightning Data Service: Eliminate Your Need to Load Records Through Controllers
 
Batchable vs @future vs Queueable
Batchable vs @future vs QueueableBatchable vs @future vs Queueable
Batchable vs @future vs Queueable
 
Salesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewSalesforce Integration Pattern Overview
Salesforce Integration Pattern Overview
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Getting started with Salesforce security
Getting started with Salesforce securityGetting started with Salesforce security
Getting started with Salesforce security
 
Integrating with salesforce
Integrating with salesforceIntegrating with salesforce
Integrating with salesforce
 

Andere mochten auch

Andere mochten auch (20)

Salesforce1 API Overview
Salesforce1 API OverviewSalesforce1 API Overview
Salesforce1 API Overview
 
Integration with the Salesforce App Cloud - Amsterdam 2016
Integration with the Salesforce App Cloud - Amsterdam 2016Integration with the Salesforce App Cloud - Amsterdam 2016
Integration with the Salesforce App Cloud - Amsterdam 2016
 
Design Patterns for Asynchronous Apex
Design Patterns for Asynchronous ApexDesign Patterns for Asynchronous Apex
Design Patterns for Asynchronous Apex
 
Spring '16 release belgium salesforce user group samuel de rycke
Spring '16 release belgium salesforce user group samuel de ryckeSpring '16 release belgium salesforce user group samuel de rycke
Spring '16 release belgium salesforce user group samuel de rycke
 
Getting Certified - proven tips for success (French Touch Dreamin)
Getting Certified - proven tips for success (French Touch Dreamin)Getting Certified - proven tips for success (French Touch Dreamin)
Getting Certified - proven tips for success (French Touch Dreamin)
 
Salesforce APIs
Salesforce APIsSalesforce APIs
Salesforce APIs
 
A Taste of Lightning in Action
A Taste of Lightning in ActionA Taste of Lightning in Action
A Taste of Lightning in Action
 
Custom Metadata Data Types
Custom Metadata Data TypesCustom Metadata Data Types
Custom Metadata Data Types
 
Salesforce Flexible Pages
Salesforce Flexible PagesSalesforce Flexible Pages
Salesforce Flexible Pages
 
Lightning Chess at the Sri Sanka Salesforce Developer Group
Lightning Chess at the Sri Sanka  Salesforce Developer GroupLightning Chess at the Sri Sanka  Salesforce Developer Group
Lightning Chess at the Sri Sanka Salesforce Developer Group
 
Advanced Apex Development - Asynchronous Processes
Advanced Apex Development - Asynchronous ProcessesAdvanced Apex Development - Asynchronous Processes
Advanced Apex Development - Asynchronous Processes
 
Salesforce World Tour Amsterdam: Guide your users through a process using path
Salesforce World Tour Amsterdam:  Guide your users through a process using pathSalesforce World Tour Amsterdam:  Guide your users through a process using path
Salesforce World Tour Amsterdam: Guide your users through a process using path
 
ABSI & ASP Summer Party 2016 - Presentation
ABSI & ASP Summer Party 2016 - PresentationABSI & ASP Summer Party 2016 - Presentation
ABSI & ASP Summer Party 2016 - Presentation
 
Lightning chess
Lightning chessLightning chess
Lightning chess
 
Absi summmer BBQ Presentation on Going Digital
Absi summmer BBQ Presentation on Going DigitalAbsi summmer BBQ Presentation on Going Digital
Absi summmer BBQ Presentation on Going Digital
 
ABSI Summer Event 2015
ABSI Summer Event 2015ABSI Summer Event 2015
ABSI Summer Event 2015
 
Enterprise Integration - Solution Patterns From the Field
Enterprise Integration - Solution Patterns From the FieldEnterprise Integration - Solution Patterns From the Field
Enterprise Integration - Solution Patterns From the Field
 
Salesforce Apex Ten Commandments
Salesforce Apex Ten CommandmentsSalesforce Apex Ten Commandments
Salesforce Apex Ten Commandments
 
Salesforce DUG - Queueable Apex
Salesforce DUG - Queueable ApexSalesforce DUG - Queueable Apex
Salesforce DUG - Queueable Apex
 
Apex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex LiberatedApex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex Liberated
 

Ähnlich wie Asynchronous Apex Salesforce World Tour Paris 2015

Spring '14 Release Developer Preview Webinar
Spring '14 Release Developer Preview WebinarSpring '14 Release Developer Preview Webinar
Spring '14 Release Developer Preview Webinar
Salesforce Developers
 
Elevate workshop programmatic_2014
Elevate workshop programmatic_2014Elevate workshop programmatic_2014
Elevate workshop programmatic_2014
David Scruggs
 

Ähnlich wie Asynchronous Apex Salesforce World Tour Paris 2015 (20)

Spring '14 Release Developer Preview Webinar
Spring '14 Release Developer Preview WebinarSpring '14 Release Developer Preview Webinar
Spring '14 Release Developer Preview Webinar
 
Intro to Apex Programmers
Intro to Apex ProgrammersIntro to Apex Programmers
Intro to Apex Programmers
 
Salesforce1 Platform for programmers
Salesforce1 Platform for programmersSalesforce1 Platform for programmers
Salesforce1 Platform for programmers
 
Coding Apps in the Cloud with Force.com - Part 2
Coding Apps in the Cloud with Force.com - Part 2Coding Apps in the Cloud with Force.com - Part 2
Coding Apps in the Cloud with Force.com - Part 2
 
Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex! Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex!
 
ELEVATE Paris
ELEVATE ParisELEVATE Paris
ELEVATE Paris
 
Spring '16 Release Preview Webinar
Spring '16 Release Preview Webinar Spring '16 Release Preview Webinar
Spring '16 Release Preview Webinar
 
Advanced Apex Webinar
Advanced Apex WebinarAdvanced Apex Webinar
Advanced Apex Webinar
 
Design Patterns Every ISV Needs to Know (October 15, 2014)
Design Patterns Every ISV Needs to Know (October 15, 2014)Design Patterns Every ISV Needs to Know (October 15, 2014)
Design Patterns Every ISV Needs to Know (October 15, 2014)
 
Developing Offline Mobile Apps with Salesforce Mobile SDK SmartStore
Developing Offline Mobile Apps with Salesforce Mobile SDK SmartStoreDeveloping Offline Mobile Apps with Salesforce Mobile SDK SmartStore
Developing Offline Mobile Apps with Salesforce Mobile SDK SmartStore
 
Quickly Create Data Sets for the Analytics Cloud
Quickly Create Data Sets for the Analytics CloudQuickly Create Data Sets for the Analytics Cloud
Quickly Create Data Sets for the Analytics Cloud
 
Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex Force.com Friday : Intro to Apex
Force.com Friday : Intro to Apex
 
Elevate workshop programmatic_2014
Elevate workshop programmatic_2014Elevate workshop programmatic_2014
Elevate workshop programmatic_2014
 
Look Ma, No Apex: Mobile Apps with RemoteObject and Mobile SDK
Look Ma, No Apex: Mobile Apps with RemoteObject and Mobile SDKLook Ma, No Apex: Mobile Apps with RemoteObject and Mobile SDK
Look Ma, No Apex: Mobile Apps with RemoteObject and Mobile SDK
 
Hands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.comHands-on Workshop: Intermediate Development with Heroku and Force.com
Hands-on Workshop: Intermediate Development with Heroku and Force.com
 
Making External Web Pages Interact With Visualforce
Making External Web Pages Interact With VisualforceMaking External Web Pages Interact With Visualforce
Making External Web Pages Interact With Visualforce
 
Bug Hunting with the Salesforce Developer Console
Bug Hunting with the Salesforce Developer ConsoleBug Hunting with the Salesforce Developer Console
Bug Hunting with the Salesforce Developer Console
 
Get ready for your platform developer i certification webinar
Get ready for your platform developer i certification   webinarGet ready for your platform developer i certification   webinar
Get ready for your platform developer i certification webinar
 
Summer '13 Developer Preview Webinar
Summer '13 Developer Preview WebinarSummer '13 Developer Preview Webinar
Summer '13 Developer Preview Webinar
 
Build Consumer-Facing Apps with Heroku Connect
Build Consumer-Facing Apps with Heroku ConnectBuild Consumer-Facing Apps with Heroku Connect
Build Consumer-Facing Apps with Heroku Connect
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Asynchronous Apex Salesforce World Tour Paris 2015

  • 2. Samuel De Rycke Salesforce MVP ABSI @SamuelDeRycke Samuel Moyson Developer ABSI @SamuelMoyson Speakers #DevZone #SalesforceWorldTour #AsyncApex
  • 3. 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 intellectual property and other litigation, risks associated with 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-Q for the most recent fiscal quarter ended July 31, 2012. This 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.
  • 4. Follow Developer Force for the Latest News @SalesforceDevs – #SalesforceDevs Developer Force – Force.com Community +Developer Force – Force.com Community Developer Force Developer Force Group
  • 5. Synchronous vs Asynchronous • Synchronous • Asynchronous Process 1 Process 2 Waiting for response Process 1 Process 2 Continues working Get response
  • 6. • Synchronous •Immediate and fast actions •Enforce single, serial, transactions •Normal governor limits • Asynchronous •Actions that should not block the rest of the process •Processes where duration is of lesser concern •Higher governor limits Synchronous vs Asynchronous
  • 7. Types of Asynchronous Apex • Batch Apex • Future Methods • Queueable • Scheduled • Continuation
  • 8. Batch Apex Use when you want to: • Process a big “batch” of records in smaller “batches” of records • Each smaller batch is handled in a discrete transaction • Monitor queue of batch jobs • Batchable context with information about batch
  • 9. Batch Apex Start Execute Finish global Database.QueryLocator start(Database.BatchableContext BC) { //Query for data return Database.getQueryLocator(query); } global void execute(Database.BatchableContext BC, List<sObject> scope) { //Do some actions with data //DML Statement } global void finish(Database.BatchableContext BC) { //Give some feedback about statistics of batch //Do post batch actions }
  • 10. Batch Apex Process up to 50 million records Monitor batch progress in the Setup User Interface Admins can reorder batch priority with Apex Flex Queue Maximum 5 concurrent batches processed (status Queued) Not always easy to debug
  • 11. Future Methods Use when you want to: • Execute methods that should not delay or respond to the current Apex transaction • Isolate transaction contexts and DML contexts • Make asynchronous call outs to Web services Pilot: Future methods with Higher Limits • Set specific governor limits for a specific method x2 or x3
  • 12. Future Methods Executepublic class MyClass { public void myNormalMethod{ List<ID> recordIds; //Synchronous logic here myFutureMethod(recordIds); // More synchronous logic } @future public static void myFutureMethod(List<ID> recordIds) { // Get those records based on the IDs // Process records } } @future
  • 13. Future Methods Executed near instantly Bypass mixed DML limitations Pilot: increase limits for specific methods Maximum 50 future methods per Apex invocation Only accepts (collections of) primitive data types Future methods can not invoke other future methods Can not be invoked from Visualforce Constructors, Get & Set
  • 14. Queueable Apex Use when you want to: • Start long-running operations and monitor them within the current process or the user interface • Pass complex types • Chain asynchronous jobs
  • 15. Queueable Apex implements Queueable ID jobID = System.enqueueJob(new MyQueueableJob ()); public class MyQueueableJob implements Queueable { //Other logic public void execute(QueueableContext context) { //Asynchronous logic here //Optionally: enqueue another job } }
  • 16. Queueable Apex Executed near instantly Unlimited depth of chained jobs (except for Dev & Trial orgs) Use sObject and Apex objects as parameters Maximum 50 jobs queued in a single apex transaction When chaining jobs only 1 ‘child job’ is supported Jobs can not be chained in test context. Chained jobs do not support callouts (Winter ‘16 ?)
  • 17. Schedulable Apex Use when you want to: • Schedule Apex classes • Specify schedule with User Interface or Apex
  • 18. Schedulable Apex // Schedulable class global class MySchedulable implements Schedulable { global void execute(SchedulableContext sc) { // Execute apex } } // Schedule from Apex: MySchedulable schApex = new MySchedulable (); String sch = '0 15 10 * * ?'; String jobID = System.schedule('MySchedulable', sch, schApex); implements Schedulable
  • 20. Schedulable Apex Execute Apex on scheduled intervals Admins can manage the schedule from the Setup UI Maximum 100 scheduled jobs at the same time Using the Setup User Interface the minimum interval is 1 hour Synchronous web service callouts are not supported
  • 21. Continuation Use when you want to: –Make callouts from Visualforce pages –Special one: synchronous asynchronous Twitter demo https://github.com/SamuelMoy/TwitterContinuationDemo
  • 23. Continuation // Visualforce page <apex:page showHeader="true" sidebar="true" controller="TwitterController"> <apex:form > <!-- Invokes the action method when the user clicks this button. --> <apex:commandButton action="{!startRequest}" value="Start" reRender="result"/> </apex:form> <!-- This output text component displays the callout response body. --> <apex:outputText id="result" value="{!status} " /> </apex:page> Visualforce
  • 24. Continuation // Action method public Object startRequest() { // Create continuation with a timeout Continuation con = new Continuation(40); // Set callback method con.continuationMethod='processResponse'; HttpRequest req = new HttpRequest(); // Add callout request to continuation this.requestLabel = con.addHttpRequest(req); // Return the continuation return con; } startRequest
  • 25. Continuation // Callback method public Object processResponse() { // Get the response by using the unique label HttpResponse response = Continuation.getResponse(this.requestLabel); // Set the result variable that is displayed on the Visualforce page this.result = response.getBody(); // Return null to re-render the original Visualforce page return null; } processResponse
  • 26. Continuation Integrate Visualforce with back-end systems No long-running concurrent request limit for call outs that last longer than 5 seconds Visualforce page suspended until action completed (= Synchronous) Maximum 3 asynchronous callouts in one single Continuation Maximum timeout continuation is 120 seconds
  • 27. Testing Asynchronous Apex • Invoke asynchronous Apex between the Test.startTest() and Test.stopTest() methods. • The Test.stopTest() method will execute all asynchronous and scheduled Apex synchronously. • Assert :-)
  • 28. Recap Batch Future Schedulable Queueable Continuation High volume of records Near instantly Primitive parameters Schedule jobs Chain jobs Complex parameters Callouts in Visualforce
  • 29. Samuel De Rycke Salesforce MVP ABSI @SamuelDeRycke Samuel Moyson Developer ABSI @SamuelMoyson Q & A
  • 31. La communauté des développeurs Salesforce en France Rejoignez la communauté de développeurs en France et venez partager votre expérience sur la plateforme Salesforce1 bit.ly/dugParis bit.ly/dugStQuentin bit.ly/dugSuisse bit.ly/dugBelgique