SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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 ApexSalesforce Developers
 
Apex Trigger in Salesforce
Apex Trigger in SalesforceApex Trigger in Salesforce
Apex Trigger in SalesforceCloud Analogy
 
All About Test Class in #Salesforce
All About Test Class in #SalesforceAll About Test Class in #Salesforce
All About Test Class in #SalesforceAmit Singh
 
Demystify Salesforce Bulk API
Demystify Salesforce Bulk APIDemystify Salesforce Bulk API
Demystify Salesforce Bulk APIDhanik Sahni
 
Design Patterns for Asynchronous Apex
Design Patterns for Asynchronous ApexDesign Patterns for Asynchronous Apex
Design Patterns for Asynchronous ApexSalesforce Developers
 
Managing Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with RelaxManaging Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with RelaxSalesforce Developers
 
Salesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewSalesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewDhanik Sahni
 
Test Classes in Salesforce
Test Classes in SalesforceTest Classes in Salesforce
Test Classes in SalesforceAtul Gupta(8X)
 
salesforce triggers interview questions and answers
salesforce triggers interview questions and answerssalesforce triggers interview questions and answers
salesforce triggers interview questions and answersbhanuadmob
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceJitendra Zaa
 
Apache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and DevelopersApache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and Developersconfluent
 
Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex codeEdwinOstos
 
Spark with Delta Lake
Spark with Delta LakeSpark with Delta Lake
Spark with Delta LakeKnoldus Inc.
 
Oracle XML Publisher / BI Publisher
Oracle XML Publisher / BI PublisherOracle XML Publisher / BI Publisher
Oracle XML Publisher / BI PublisherEdi Yanto
 
What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019
What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019
What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019confluent
 

Mais procurados (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
 
Apex Trigger in Salesforce
Apex Trigger in SalesforceApex Trigger in Salesforce
Apex Trigger in Salesforce
 
All About Test Class in #Salesforce
All About Test Class in #SalesforceAll About Test Class in #Salesforce
All About Test Class in #Salesforce
 
Demystify Salesforce Bulk API
Demystify Salesforce Bulk APIDemystify Salesforce Bulk API
Demystify Salesforce Bulk API
 
Design Patterns for Asynchronous Apex
Design Patterns for Asynchronous ApexDesign Patterns for Asynchronous Apex
Design Patterns for Asynchronous Apex
 
Managing Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with RelaxManaging Your Batch and Scheduled Apex Processes with Relax
Managing Your Batch and Scheduled Apex Processes with Relax
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Deep Dive into Apex Triggers
Deep Dive into Apex TriggersDeep Dive into Apex Triggers
Deep Dive into Apex Triggers
 
Salesforce Integration Pattern Overview
Salesforce Integration Pattern OverviewSalesforce Integration Pattern Overview
Salesforce Integration Pattern Overview
 
Test Classes in Salesforce
Test Classes in SalesforceTest Classes in Salesforce
Test Classes in Salesforce
 
salesforce triggers interview questions and answers
salesforce triggers interview questions and answerssalesforce triggers interview questions and answers
salesforce triggers interview questions and answers
 
Apex Testing Best Practices
Apex Testing Best PracticesApex Testing Best Practices
Apex Testing Best Practices
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
 
Apache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and DevelopersApache Kafka Fundamentals for Architects, Admins and Developers
Apache Kafka Fundamentals for Architects, Admins and Developers
 
Introduction to apex code
Introduction to apex codeIntroduction to apex code
Introduction to apex code
 
Spark with Delta Lake
Spark with Delta LakeSpark with Delta Lake
Spark with Delta Lake
 
Oracle XML Publisher / BI Publisher
Oracle XML Publisher / BI PublisherOracle XML Publisher / BI Publisher
Oracle XML Publisher / BI Publisher
 
What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019
What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019
What's the time? ...and why? (Mattias Sax, Confluent) Kafka Summit SF 2019
 
Relationships in Salesforce
Relationships in SalesforceRelationships in Salesforce
Relationships in Salesforce
 

Destaque

Salesforce1 API Overview
Salesforce1 API OverviewSalesforce1 API Overview
Salesforce1 API OverviewSamuel De Rycke
 
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 2016Samuel De Rycke
 
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 ryckeSamuel 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)Samuel De Rycke
 
A Taste of Lightning in Action
A Taste of Lightning in ActionA Taste of Lightning in Action
A Taste of Lightning in ActionSteven Hugo
 
Custom Metadata Data Types
Custom Metadata Data TypesCustom Metadata Data Types
Custom Metadata Data TypesSamuel Moyson
 
Salesforce Flexible Pages
Salesforce Flexible PagesSalesforce Flexible Pages
Salesforce Flexible PagesSamuel De Rycke
 
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 GroupSamuel De Rycke
 
Advanced Apex Development - Asynchronous Processes
Advanced Apex Development - Asynchronous ProcessesAdvanced Apex Development - Asynchronous Processes
Advanced Apex Development - Asynchronous ProcessesSalesforce Developers
 
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 pathLieven Juwet
 
ABSI & ASP Summer Party 2016 - Presentation
ABSI & ASP Summer Party 2016 - PresentationABSI & ASP Summer Party 2016 - Presentation
ABSI & ASP Summer Party 2016 - PresentationJulie Minner
 
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 DigitalABSI_NV
 
ABSI Summer Event 2015
ABSI Summer Event 2015ABSI Summer Event 2015
ABSI Summer Event 2015ABSI_NV
 
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 FieldSalesforce Developers
 
Salesforce Apex Ten Commandments
Salesforce Apex Ten CommandmentsSalesforce Apex Ten Commandments
Salesforce Apex Ten CommandmentsNetStronghold
 
Apex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex LiberatedApex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex LiberatedCarolEnLaNube
 
The Marketing Technology Game of Thrones
The Marketing Technology Game of ThronesThe Marketing Technology Game of Thrones
The Marketing Technology Game of ThronesPardot
 

Destaque (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
 
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
 
Apex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex LiberatedApex Flex Queue: Batch Apex Liberated
Apex Flex Queue: Batch Apex Liberated
 
Apex Nirvana
Apex NirvanaApex Nirvana
Apex Nirvana
 
The Marketing Technology Game of Thrones
The Marketing Technology Game of ThronesThe Marketing Technology Game of Thrones
The Marketing Technology Game of Thrones
 

Semelhante a 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 WebinarSalesforce Developers
 
Salesforce1 Platform for programmers
Salesforce1 Platform for programmersSalesforce1 Platform for programmers
Salesforce1 Platform for programmersSalesforce Developers
 
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 2Salesforce Developers
 
Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex! Dive Deep into Apex: Advanced Apex!
Dive Deep into Apex: Advanced Apex! Salesforce Developers
 
Advanced Apex Webinar
Advanced Apex WebinarAdvanced Apex Webinar
Advanced Apex Webinarpbattisson
 
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)Salesforce Partners
 
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 SmartStoreTom Gersic
 
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 CloudSalesforce Developers
 
Elevate workshop programmatic_2014
Elevate workshop programmatic_2014Elevate workshop programmatic_2014
Elevate workshop programmatic_2014David Scruggs
 
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 SDKSalesforce Developers
 
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.comSalesforce Developers
 
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 VisualforceSalesforce Developers
 
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 ConsoleMatthew Poe
 
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 webinarJackGuo20
 
Summer '13 Developer Preview Webinar
Summer '13 Developer Preview WebinarSummer '13 Developer Preview Webinar
Summer '13 Developer Preview WebinarSalesforce Developers
 
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 ConnectJeff Douglas
 

Semelhante a 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
 

Último

JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native BuildpacksVish Abrams
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Incrobinwilliams8624
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.Sharon Liu
 

Último (20)

JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native Buildpacks
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Inc
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
 

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