SlideShare a Scribd company logo
Leveraging Javascript Promises
and the Bulk API
​ Jim Rae
​ Cloud Solutions Practice Lead
​ jrae@xede.com
​ @jimraeSFDC
​ 
HTML5, JSForce, Javascript Promises and More
u  Overview
u  What are Javascript Promises
u  JSForce and the Bulk API
u  HTML5 FileReader
u  Summary
Agenda
This session will educate you on how to apply a Javascript application of the various APIs (via
JSForce) combined with Promises techniques to optimize asynchronous processing.
Examples include:
u  Allowing long running processes to continue in background, and provide updates to the user
u  Process large volumes of data into and out of salesforce.com
u  Execute complex query against very large dataset
u  External callouts to webservices
Overview
​ A Promise represents a proxy for a value not necessarily known when the
promise is created. It allows you to associate handlers to an asynchronous
action's eventual success value or failure reason. This lets asynchronous methods
return values like synchronous methods: instead of the final value, the
asynchronous method returns a promise of having a value at some point in the
future*
What are Javascript Promises
*https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
u Promises allow you to flatten your
asynchronous API calls an remove the
“Pyramid of Doom” (or Callback Hell)
u Promises allow you to choose when
you want to handle the result of an
asynchronous call
u Promises can be chained, and chains
can be extended at any time
u Promises allow you to effortlessly
handle errors, even when chaining
Why are they better
What are Javascript Promises
*https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
​ A promise can be:
•  fulfilled The action relating to the promise succeeded
•  rejected The action relating to the promise failed
•  pending Hasn't fulfilled or rejected yet settled Has fulfilled or rejected
You will also hear the term “then-able” to describe an object that is promise-like, in that it has a “then”
method.
What are Javascript Promises
​ Promise Methods include:
•  Promise.all(iterable) Accepts an iterable array of promises and resolves as a new promise when all
promises in the iterable are resolved
•  Promise.race(iterable) Accepts an iterable array of promises like the All method, but resolves to a new
promise when the first element in the array is resolved
•  Promise.reject(reason) Returns a promise object that is already rejected with the specified reason
•  Promise.resolve(value) Returns a resolved promise with the specified value
•  Promise.then(onFulfilled,onRejected) Appends the fulfill and reject handlers to the new promise
•  Promise.catch(onRejected) Appends a reject handler to the promise
What are Javascript Promises
Callback style
fs.readFile("myFile.txt", function(err, fileContents){
if(!!err) {
throw Error(err);
return;
}
myConvertFile(fileContents, function(err, newContents){
if(!!err){
throw Error(err);
return;
}
fs.writeFile('myNewFile.txt', newFileContents, function(err, saved){
if(!!err){
throw Error(err);
return;
}
console.log("YAY! SAVED FILE!");
}
}
Promise style
fs = Promise.promisifyAll(fs);
myConvertFile = Promise.promisify(myConvertFile);
myWriteFile = Promise.promisify(
fs.readFileAsync("myFile.txt")
.then(myConvertFile)
.then(function(newFileContents){
return fs.writeFileAsync('myNewFile.txt’,newFileContents);
})
.then(console.log.bind(console))
.catch(function(err){
console.err("Error:", err);
});
What are Javascript Promises
Sample code source: http://blog.namangoel.com/dealing-with-callback-hell
Let’s Look at the Code
Javascript Promises
JSForce (jsforce.github.io) is a Javascript library that encapsulates Salesforce APIs into asynchronous
JavaScript function calls. It works both on the Client and Server side, and with Node.js as well as
Javascript
Included APIS:
u  REST API
u  Apex REST
u  Analytics API
u  Bulk API
u  Chatter API
u  Metadata API
u  Streaming API
u  Tooling API
JSForce and the Bulk API
Using the JSForce Library on a Visualforce
page is a straightforward process. Simply
download the library from jsforce.github.io/
download and create a Static Resource in
your org. Then, include the resource as a
script in the header of your page.
<apex:page standardcontroller=”Contact”
docType="html-5.0”
title="Bulk Contact Processor" >
<apex:includeScript
value="{!
URLFOR($Resource.JSforce)}" />
<script>
//script here
</script>
<apex:pageblock>
//Show stuff here
</apex:pageblock>
</apex:page>
JSForce and the Bulk API
​ Getting Started
The Salesforce Bulk (or Batch) API is a RESTful API that is optimal for loading or deleting large sets
of data. You can use it to query, insert, update, upsert, or delete a large number of records
asynchronously by submitting batches that Salesforce processes in the background.
You first send a number of batches to the server using an HTTP POST call and then the server
processes the batches in the background.
While batches are being processed, you can track progress by checking the status of the job using
an HTTP GET call.
All operations use HTTP GET or POST methods to send and receive XML or CSV data.
JSForce and the Bulk API
Source: https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch
Let’s Look at the Code
Javascript and JSForce
The FileReader object lets web
applications asynchronously read
the contents of files (or raw data
buffers) stored on the user's
computer, using File or Blob
objects to specify the file or data
to read.
File objects may be obtained
from a FileList object returned as
a result of a user selecting files
using the <input> element, from
a drag and drop operation's
DataTransfer object, or from the
mozGetAsFile() API on an
HTMLCanvasElement.
When leveraging the FileReader
API, you should first verify it is
supported on the users browser.
​ Check for browser support
​ if (window.File && window.FileReader && window.FileList && window.Blob) {
​  // Great success! All the File APIs are supported.
​ } else {
​  alert('The File APIs are not fully supported in this browser.');
​ }
​ Get the File(s)
​ <input type="file" id="files" name="files[]" multiple />
<script>
​ //process the file here
​ </script>
HTML5 FileReader
Source: https://developer.mozilla.org/en-US/docs/Web/API/FileReader
CanIuse.com
HTML5 FileReader
Source: CanIuse.com
Let’s Put it all Together
​ In this session we have looked at :
u  Promises – What are they, and what are they good for?
u  JSForce – How to leverage this library to expose the suite of Salesforce APIs to your Javascript
u  Salesforce Bulk API – How to work with large volumes of data in “record time” (pun intended)
u  HTML5 FileReader – How to use the FileReader as one method of getting data into Salesforce
via Javascript
u  Use Cases:
u  Bulk File upload
u  Large dataset query and summary
u  Calling External Webservices
u  Execute and Monitor long running processes
Summary
Q & A
​ Promises – https://promisesaplus.com
​ JSForce – https://jsforce.github.io
​ Demo Files – https://github.com/jimrae/df15Demo
Where can I get the code and learn more
19
Thank you
20

More Related Content

What's hot

Salesforce Flows Architecture Best Practices
Salesforce Flows Architecture Best PracticesSalesforce Flows Architecture Best Practices
Salesforce Flows Architecture Best Practicespanayaofficial
 
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabnerPerformance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabnerStephen Thair
 
Connecticut Salesforce Developer Group - Jan 2017
Connecticut Salesforce Developer Group - Jan 2017Connecticut Salesforce Developer Group - Jan 2017
Connecticut Salesforce Developer Group - Jan 2017Jitendra Zaa
 
Synthetic web performance testing with Selenium
Synthetic web performance testing with SeleniumSynthetic web performance testing with Selenium
Synthetic web performance testing with SeleniumAndriy Samilyak
 
5 Things I Wish I'd Known about Microservices
5 Things I Wish I'd Known about Microservices5 Things I Wish I'd Known about Microservices
5 Things I Wish I'd Known about MicroservicesAtlassian
 
Client side performance analysis
Client side performance analysisClient side performance analysis
Client side performance analysisTsimafei Avilin
 
Improve collaboration and confidence with Consumer-driven contracts
Improve collaboration and confidence with Consumer-driven contractsImprove collaboration and confidence with Consumer-driven contracts
Improve collaboration and confidence with Consumer-driven contractsPierre Vincent
 
Bring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeBring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeColdFusionConference
 
How to Troubleshoot & Optimize Database Query Performance for Your Application
How to Troubleshoot  & Optimize Database Query Performance for Your ApplicationHow to Troubleshoot  & Optimize Database Query Performance for Your Application
How to Troubleshoot & Optimize Database Query Performance for Your ApplicationDynatrace
 
DeepCrawl Webinar: Performing SEO on the Edge
DeepCrawl Webinar: Performing SEO on the EdgeDeepCrawl Webinar: Performing SEO on the Edge
DeepCrawl Webinar: Performing SEO on the EdgeDan Taylor
 
Apex code Benchmarking
Apex code BenchmarkingApex code Benchmarking
Apex code BenchmarkingAmit Chaudhary
 
Using Automation to Meet Demands for Performance and Quality
Using Automation to Meet Demands for Performance and QualityUsing Automation to Meet Demands for Performance and Quality
Using Automation to Meet Demands for Performance and QualityNeotys
 
How to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeter
How to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeterHow to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeter
How to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeterAlon Girmonsky
 
Salesforce Process builder Vs Workflows
Salesforce Process builder Vs WorkflowsSalesforce Process builder Vs Workflows
Salesforce Process builder Vs WorkflowsPrasanna Deshpande ☁
 

What's hot (20)

Workflows and Digital Signatures
Workflows and Digital SignaturesWorkflows and Digital Signatures
Workflows and Digital Signatures
 
Salesforce asynchronous apex
Salesforce asynchronous apexSalesforce asynchronous apex
Salesforce asynchronous apex
 
Salesforce Flows Architecture Best Practices
Salesforce Flows Architecture Best PracticesSalesforce Flows Architecture Best Practices
Salesforce Flows Architecture Best Practices
 
Introduction to Apex Triggers
Introduction to Apex TriggersIntroduction to Apex Triggers
Introduction to Apex Triggers
 
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabnerPerformance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
 
Connecticut Salesforce Developer Group - Jan 2017
Connecticut Salesforce Developer Group - Jan 2017Connecticut Salesforce Developer Group - Jan 2017
Connecticut Salesforce Developer Group - Jan 2017
 
Synthetic web performance testing with Selenium
Synthetic web performance testing with SeleniumSynthetic web performance testing with Selenium
Synthetic web performance testing with Selenium
 
5 Things I Wish I'd Known about Microservices
5 Things I Wish I'd Known about Microservices5 Things I Wish I'd Known about Microservices
5 Things I Wish I'd Known about Microservices
 
Client side performance analysis
Client side performance analysisClient side performance analysis
Client side performance analysis
 
Improve collaboration and confidence with Consumer-driven contracts
Improve collaboration and confidence with Consumer-driven contractsImprove collaboration and confidence with Consumer-driven contracts
Improve collaboration and confidence with Consumer-driven contracts
 
Bring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC PlungeBring Order to the Chaos: Take the MVC Plunge
Bring Order to the Chaos: Take the MVC Plunge
 
How to Troubleshoot & Optimize Database Query Performance for Your Application
How to Troubleshoot  & Optimize Database Query Performance for Your ApplicationHow to Troubleshoot  & Optimize Database Query Performance for Your Application
How to Troubleshoot & Optimize Database Query Performance for Your Application
 
Performance with Selenium2
Performance with Selenium2Performance with Selenium2
Performance with Selenium2
 
DeepCrawl Webinar: Performing SEO on the Edge
DeepCrawl Webinar: Performing SEO on the EdgeDeepCrawl Webinar: Performing SEO on the Edge
DeepCrawl Webinar: Performing SEO on the Edge
 
Apex code Benchmarking
Apex code BenchmarkingApex code Benchmarking
Apex code Benchmarking
 
Using Automation to Meet Demands for Performance and Quality
Using Automation to Meet Demands for Performance and QualityUsing Automation to Meet Demands for Performance and Quality
Using Automation to Meet Demands for Performance and Quality
 
How to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeter
How to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeterHow to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeter
How to Run a 1,000,000 VU Load Test using Apache JMeter and BlazeMeter
 
Workflow in Salesforce
Workflow in SalesforceWorkflow in Salesforce
Workflow in Salesforce
 
Salesforce Process builder Vs Workflows
Salesforce Process builder Vs WorkflowsSalesforce Process builder Vs Workflows
Salesforce Process builder Vs Workflows
 
When the connection fails
When the connection failsWhen the connection fails
When the connection fails
 

Similar to Leveraging JavaScript Promises and the Bulk API

How to ensure Presto scalability 
in multi use case
How to ensure Presto scalability 
in multi use case How to ensure Presto scalability 
in multi use case
How to ensure Presto scalability 
in multi use case Kai Sasaki
 
Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6Devang Garach
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 RecipesJosh Juneau
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsRapidValue
 
En story of cakephp2.0
En story of cakephp2.0En story of cakephp2.0
En story of cakephp2.0Hiroki Shimizu
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in reactBOSC Tech Labs
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Web Directions
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
Academy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageAcademy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageBinary Studio
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Joe Ferguson
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep DiveGabriel Walt
 
Flex In Portal Final
Flex In Portal   FinalFlex In Portal   Final
Flex In Portal FinalSunil Patil
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Joe Ferguson
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!Evan Mullins
 
25+ Reasons to use OmniFaces in JSF applications
25+ Reasons to use OmniFaces in JSF applications25+ Reasons to use OmniFaces in JSF applications
25+ Reasons to use OmniFaces in JSF applicationsAnghel Leonard
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Developmentjoelabrahamsson
 

Similar to Leveraging JavaScript Promises and the Bulk API (20)

How to ensure Presto scalability 
in multi use case
How to ensure Presto scalability 
in multi use case How to ensure Presto scalability 
in multi use case
How to ensure Presto scalability 
in multi use case
 
Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6Advanced JavaScript - Internship Presentation - Week6
Advanced JavaScript - Internship Presentation - Week6
 
Java EE 7 Recipes
Java EE 7 RecipesJava EE 7 Recipes
Java EE 7 Recipes
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
 
Woa. Reloaded
Woa. ReloadedWoa. Reloaded
Woa. Reloaded
 
En story of cakephp2.0
En story of cakephp2.0En story of cakephp2.0
En story of cakephp2.0
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5Dave Orchard - Offline Web Apps with HTML5
Dave Orchard - Offline Web Apps with HTML5
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Academy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storageAcademy PRO: HTML5 Data storage
Academy PRO: HTML5 Data storage
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Advanced JavaScript
Advanced JavaScriptAdvanced JavaScript
Advanced JavaScript
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015 Acceptance & Functional Testing with Codeception - Devspace 2015
Acceptance & Functional Testing with Codeception - Devspace 2015
 
AEM Sightly Deep Dive
AEM Sightly Deep DiveAEM Sightly Deep Dive
AEM Sightly Deep Dive
 
Flex In Portal Final
Flex In Portal   FinalFlex In Portal   Final
Flex In Portal Final
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
 
25+ Reasons to use OmniFaces in JSF applications
25+ Reasons to use OmniFaces in JSF applications25+ Reasons to use OmniFaces in JSF applications
25+ Reasons to use OmniFaces in JSF applications
 
Progressive EPiServer Development
Progressive EPiServer DevelopmentProgressive EPiServer Development
Progressive EPiServer Development
 

More from Salesforce Developers

Sample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSample Gallery: Reference Code and Best Practices for Salesforce Developers
Sample Gallery: Reference Code and Best Practices for Salesforce DevelopersSalesforce Developers
 
Maximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceMaximizing Salesforce Lightning Experience and Lightning Component Performance
Maximizing Salesforce Lightning Experience and Lightning Component PerformanceSalesforce Developers
 
Local development with Open Source Base Components
Local development with Open Source Base ComponentsLocal development with Open Source Base Components
Local development with Open Source Base ComponentsSalesforce Developers
 
TrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsTrailheaDX India : Developer Highlights
TrailheaDX India : Developer HighlightsSalesforce Developers
 
Why developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaWhy developers shouldn’t miss TrailheaDX India
Why developers shouldn’t miss TrailheaDX IndiaSalesforce Developers
 
CodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentCodeLive: Build Lightning Web Components faster with Local Development
CodeLive: Build Lightning Web Components faster with Local DevelopmentSalesforce Developers
 
CodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsCodeLive: Converting Aura Components to Lightning Web Components
CodeLive: Converting Aura Components to Lightning Web ComponentsSalesforce Developers
 
Enterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsEnterprise-grade UI with open source Lightning Web Components
Enterprise-grade UI with open source Lightning Web ComponentsSalesforce Developers
 
TrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsTrailheaDX and Summer '19: Developer Highlights
TrailheaDX and Summer '19: Developer HighlightsSalesforce Developers
 
Lightning web components - Episode 4 : Security and Testing
Lightning web components  - Episode 4 : Security and TestingLightning web components  - Episode 4 : Security and Testing
Lightning web components - Episode 4 : Security and TestingSalesforce Developers
 
LWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilityLWC Episode 3- Component Communication and Aura Interoperability
LWC Episode 3- Component Communication and Aura InteroperabilitySalesforce Developers
 
Lightning web components episode 2- work with salesforce data
Lightning web components   episode 2- work with salesforce dataLightning web components   episode 2- work with salesforce data
Lightning web components episode 2- work with salesforce dataSalesforce Developers
 
Lightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionLightning web components - Episode 1 - An Introduction
Lightning web components - Episode 1 - An IntroductionSalesforce Developers
 
Migrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPMigrating CPQ to Advanced Calculator and JSQCP
Migrating CPQ to Advanced Calculator and JSQCPSalesforce Developers
 
Scale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceScale with Large Data Volumes and Big Objects in Salesforce
Scale with Large Data Volumes and Big Objects in SalesforceSalesforce Developers
 
Replicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureReplicate Salesforce Data in Real Time with Change Data Capture
Replicate Salesforce Data in Real Time with Change Data CaptureSalesforce Developers
 
Modern Development with Salesforce DX
Modern Development with Salesforce DXModern Development with Salesforce DX
Modern Development with Salesforce DXSalesforce Developers
 
Integrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectIntegrate CMS Content Into Lightning Communities with CMS Connect
Integrate CMS Content Into Lightning Communities with CMS ConnectSalesforce Developers
 

More from Salesforce Developers (20)

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

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsVlad Stirbu
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoTAnalytics
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Alison B. Lowndes
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 

Leveraging JavaScript Promises and the Bulk API

  • 1. Leveraging Javascript Promises and the Bulk API ​ Jim Rae ​ Cloud Solutions Practice Lead ​ jrae@xede.com ​ @jimraeSFDC ​  HTML5, JSForce, Javascript Promises and More
  • 2. u  Overview u  What are Javascript Promises u  JSForce and the Bulk API u  HTML5 FileReader u  Summary Agenda
  • 3. This session will educate you on how to apply a Javascript application of the various APIs (via JSForce) combined with Promises techniques to optimize asynchronous processing. Examples include: u  Allowing long running processes to continue in background, and provide updates to the user u  Process large volumes of data into and out of salesforce.com u  Execute complex query against very large dataset u  External callouts to webservices Overview
  • 4. ​ A Promise represents a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers to an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of the final value, the asynchronous method returns a promise of having a value at some point in the future* What are Javascript Promises *https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
  • 5. u Promises allow you to flatten your asynchronous API calls an remove the “Pyramid of Doom” (or Callback Hell) u Promises allow you to choose when you want to handle the result of an asynchronous call u Promises can be chained, and chains can be extended at any time u Promises allow you to effortlessly handle errors, even when chaining Why are they better What are Javascript Promises *https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
  • 6. ​ A promise can be: •  fulfilled The action relating to the promise succeeded •  rejected The action relating to the promise failed •  pending Hasn't fulfilled or rejected yet settled Has fulfilled or rejected You will also hear the term “then-able” to describe an object that is promise-like, in that it has a “then” method. What are Javascript Promises
  • 7. ​ Promise Methods include: •  Promise.all(iterable) Accepts an iterable array of promises and resolves as a new promise when all promises in the iterable are resolved •  Promise.race(iterable) Accepts an iterable array of promises like the All method, but resolves to a new promise when the first element in the array is resolved •  Promise.reject(reason) Returns a promise object that is already rejected with the specified reason •  Promise.resolve(value) Returns a resolved promise with the specified value •  Promise.then(onFulfilled,onRejected) Appends the fulfill and reject handlers to the new promise •  Promise.catch(onRejected) Appends a reject handler to the promise What are Javascript Promises
  • 8. Callback style fs.readFile("myFile.txt", function(err, fileContents){ if(!!err) { throw Error(err); return; } myConvertFile(fileContents, function(err, newContents){ if(!!err){ throw Error(err); return; } fs.writeFile('myNewFile.txt', newFileContents, function(err, saved){ if(!!err){ throw Error(err); return; } console.log("YAY! SAVED FILE!"); } } Promise style fs = Promise.promisifyAll(fs); myConvertFile = Promise.promisify(myConvertFile); myWriteFile = Promise.promisify( fs.readFileAsync("myFile.txt") .then(myConvertFile) .then(function(newFileContents){ return fs.writeFileAsync('myNewFile.txt’,newFileContents); }) .then(console.log.bind(console)) .catch(function(err){ console.err("Error:", err); }); What are Javascript Promises Sample code source: http://blog.namangoel.com/dealing-with-callback-hell
  • 9. Let’s Look at the Code Javascript Promises
  • 10. JSForce (jsforce.github.io) is a Javascript library that encapsulates Salesforce APIs into asynchronous JavaScript function calls. It works both on the Client and Server side, and with Node.js as well as Javascript Included APIS: u  REST API u  Apex REST u  Analytics API u  Bulk API u  Chatter API u  Metadata API u  Streaming API u  Tooling API JSForce and the Bulk API
  • 11. Using the JSForce Library on a Visualforce page is a straightforward process. Simply download the library from jsforce.github.io/ download and create a Static Resource in your org. Then, include the resource as a script in the header of your page. <apex:page standardcontroller=”Contact” docType="html-5.0” title="Bulk Contact Processor" > <apex:includeScript value="{! URLFOR($Resource.JSforce)}" /> <script> //script here </script> <apex:pageblock> //Show stuff here </apex:pageblock> </apex:page> JSForce and the Bulk API ​ Getting Started
  • 12. The Salesforce Bulk (or Batch) API is a RESTful API that is optimal for loading or deleting large sets of data. You can use it to query, insert, update, upsert, or delete a large number of records asynchronously by submitting batches that Salesforce processes in the background. You first send a number of batches to the server using an HTTP POST call and then the server processes the batches in the background. While batches are being processed, you can track progress by checking the status of the job using an HTTP GET call. All operations use HTTP GET or POST methods to send and receive XML or CSV data. JSForce and the Bulk API Source: https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch
  • 13. Let’s Look at the Code Javascript and JSForce
  • 14. The FileReader object lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read. File objects may be obtained from a FileList object returned as a result of a user selecting files using the <input> element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement. When leveraging the FileReader API, you should first verify it is supported on the users browser. ​ Check for browser support ​ if (window.File && window.FileReader && window.FileList && window.Blob) { ​  // Great success! All the File APIs are supported. ​ } else { ​  alert('The File APIs are not fully supported in this browser.'); ​ } ​ Get the File(s) ​ <input type="file" id="files" name="files[]" multiple /> <script> ​ //process the file here ​ </script> HTML5 FileReader Source: https://developer.mozilla.org/en-US/docs/Web/API/FileReader
  • 16. Let’s Put it all Together
  • 17. ​ In this session we have looked at : u  Promises – What are they, and what are they good for? u  JSForce – How to leverage this library to expose the suite of Salesforce APIs to your Javascript u  Salesforce Bulk API – How to work with large volumes of data in “record time” (pun intended) u  HTML5 FileReader – How to use the FileReader as one method of getting data into Salesforce via Javascript u  Use Cases: u  Bulk File upload u  Large dataset query and summary u  Calling External Webservices u  Execute and Monitor long running processes Summary
  • 18. Q & A
  • 19. ​ Promises – https://promisesaplus.com ​ JSForce – https://jsforce.github.io ​ Demo Files – https://github.com/jimrae/df15Demo Where can I get the code and learn more 19