SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
JavaScript-heavy
Salesforce Applications
David Meyer
Technical Architect, Appirio
dmeyer@appirio.com
Andrew Davis
Consultant, Appirio
adavis@appirio.com
The role of JavaScript in Salesforce
JS is the ‘last mile’ between Salesforce and users (it already powers much
of the Salesforce UI)
The relevance of JS continues to grow (Angular, node.js, mongoDB, etc.)
Salesforce continues to expand the options for using JavaScript (Lightning
Components, Lightning Experience)
Justifications: When to go JavaScript-heavy?
If you need a highly-customized and responsive UI
If you need/want to use JS Frameworks (Angular, Backbone, etc.)
To achieve tight integration with other JS tools or web services
To bypass Salesforce governor limits
To make more complex asynchronous calls than is possible with Apex
Sample uses of JavaScript in the AOL Support Console
​  Account info derived
from back-end systems
​  Dynamically-sourced
customer offers
​ Displaying information from backend systems using browser-based REST APIs
​  Entirely custom
JavaScript applications
can be included in SFDC
​  … that draw data from
external systems
​  … and allow purchases
and other actions to be
performed on those
external systems
Sample uses of JavaScript in the AOL Support Console
​ Embedding entirely custom apps inside of Salesforce
Salesforce-JavaScript Interaction
Behind-the-scenes: Visualforce compiles down to HTML and JavaScript
Tools you can use:
• Remote Objects (JS data structures that mirror the SFDC database)
• Remote Actions (Defined in Apex, invoked from JS using JS callbacks)
• Action Methods (Action Functions, Action Support, Action Pollers)
• REST web services (Salesforce provides many and lets you write your own too)
• Lightning Components (learn more elsewhere)
• Tip: exchange complex objects between Apex and JS using JSON.de/serialize()
• Tip: overcome cross-org limitations by using JSONP or CORS-enabled services
Salesforce-JavaScript Interaction
How to pass control and data back and forth
JavaScript Concepts
Some core ideas to help Salesforce developers
JavaScript Concepts
Most developers know some JavaScript
It’s worth getting to know it well!
What we’ll touch on:
• Object-oriented JavaScript (properties, methods, protoypes)
• Asynchronous JavaScript: (callbacks and promises)
• Variable scope in JavaScript (scope, closures, namespacing)
Selecting Elements in Visualforce Pages
The Id that Visualforce gave them when it renders your pageThe Id you gave to your elements
Try this method instead (this also works in CSS)These methods won’t work to select this element
Minimize use of global variables
Having all of your variables in the global scope is poor practice, makes debugging harder, and there are
950 global variables used in Salesforce that your variable names might conflict withIdeally, create a single global “namespace” object and make your code into its methods and properties
Group Related Variables into Objects
JSON.parse and JSON.stringify provide an elegant way to pass complex data
Understanding Variable Scope and Closures
Promises and the jQuery Deferred Object
Deferred objects allow for concise and clear expression of how asynchronous requests should be handled
Debugging JavaScript using Chrome DevTools
Getting to know the capabilities of Chrome DevTools or Firebug is essential
Capabilities of DevTools:
• Inspect and modify HTML, CSS, JS, browser data
• Monitor network traffic and page rendering timeline
• Set breakpoints and step through JS execution
• Emulate devices and network speeds
• Profile and Audit your JavaScript and page loads
DevTools can give you complete visibility into every aspect of your JS
Unit Testing JavaScript on Salesforce
Setting up a unit testing framework and preparing your code
Unit testing JavaScript on Salesforce
Why unit test your JavaScript?
Setting up a unit testing stack: Node-Karma-Mocha-Chai (locally or in CI)
Preparing your code:
• Try to move all of your JS into static resources (this can also speed page load)
• But {!controllerBindings} need to stay on the Visualforce page
• Make sure your code is testable:
• Testable methods need to be globally-accessible
• Emphasize discrete, independent functions that don’t depend on global values
Write unit tests using Mocha and Chai syntax with Sinon for stubs/mocks
Sample Unit Testing Stack
For installing
dependenciesPlatform
Test Runner
(Creates a web server)
Assertion Syntax
assert.typeOf(foo, 'string');
assert.equal(foo, 'bar');
assert.lengthOf(foo, 3);
Mocks & Stubs
var callback = sinon.stub();
callback.withArgs(42).returns(1);
callback.withArgs(1).throws("TypeError");
Testing & Reporting
(The core test framework)
describe('testFn Suite', function () {
it('should return true', function () {
assert.equal(true, testFn() );
});
});
Unit testing stack setup (on your machine)
1.  Install Node.js on your development machine(s).
2.  Grab our code at goo.gl/fMFrm1 (github.com/abd3/DF15-JS-Heavy-Salesforce)
3.  Copy these files from our sample project into yours and customize as needed:
a.  /package.json - Node.js will use this to get all the packages you need
b.  /karma.conf.js - The configuration file for Karma (which files to test, etc.)
c.  /test/* - The actual unit tests used in our sample project
4.  In the root of your development directory (where package.json is installed) run
the following one-time installation command from the command line:
npm install
5.  Run the following code from the command-line every time you want to start the
karma test runner:
./node_modules/karma/bin/karma start karma.conf.js
6.  autowatch = true in our sample configuration file, so Karma will re-run all the unit
tests each time you save a change to one of the files being tested.
Unit Test FilesSalesforce Files
Anatomy of a JavaScript Unit Test
Salesforce Files
Unit Test Files
Similar Unit Tests can be Grouped
Salesforce Files
Setup & Tear-down steps
Actual Unit Tests
Setup & Tear-down steps
Setup & Tear-down steps
Anatomy of a JavaScript Unit Test
Actual Unit Tests
Anatomy of a JavaScript Unit Test
Karma’s unit testing interface
Command-line or web-based
Browser-based test runner
The command-line test runner auto-runs when files change
Karma’s code coverage report (karma-junit-reporter style)
This shows aggregate and line-by-line unit test coverage on the project
Aggregate code-coverage for the project
Line-by-line code coverage
Unit testing stack (for Continuous Integration)
​ General guidelines for including JS unit testing in your CI builds:
•  Set up a separate build step for the JS unit testing
•  Install the nodejs plugin for Jenkins and specify your version of node & npm
•  The build step consists simply of running this shell command:
npm install
node_modules/karma/bin/karma start karma.conf.js --single-run
•  The build step will succeed or fail based on the results of that command
•  This will also output some reports in the /reports folder that can be ingested to
report on code coverage, code quality, etc. if you’re using code quality tools
​  Build step for JS code
quality analysis in
SonarQube
JavaScript Unit Testing as a Continuous Deployment Step
​ JS unit testing can be one step in a CI/CD setup
​  Build step to run
JavaScript unit tests
Jenkins build step to
deploy to a QA org. This
also runs Apex unit tests
Karma outputs, displayed in SonarQube
Karma’s unit testing output can be ingested and displayed in other products
Questions & Answers
Grab the code at goo.gl/fMFrm1
(https://github.com/abd3/DF15-JS-Heavy-Salesforce)
Share Your Feedback, and Win a GoPro!
3
Earn a GoPro prize entry for
each completed survey
Tap the bell to take a
survey2Enroll in a session1
Thank you
Salesforce - JavaScript Integration Methods
Note that you can mix and match any combination of these as needed
Action Methods
JavaScript
Remoting
Remote Objects
Salesforce
REST API
Require
Controller Code
yes yes no no
Require
Visualforce
yes yes yes no
Have their own
Governor Limits
no no no yes
Main Benefit
Call static or
instance methods
while maintaining
controller state
Call static Apex
methods quickly and
efficiently
Create a JS version
of Salesforce object
with CRUD access
Perform Salesforce
actions and modify
data from external
apps
Main
Disadvantage
Submits form data;
slower
Limited to static
methods
Can’t execute
custom Apex from
VF this way

Contenu connexe

Tendances

Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep DiveSalesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep DiveSalesforce Developers
 
Generically Call External Classes from Managed Packages
Generically Call External Classes from Managed PackagesGenerically Call External Classes from Managed Packages
Generically Call External Classes from Managed PackagesSalesforce Developers
 
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)Salesforce Developers
 
Salesforce Apex Hours:- Salesforce DX
Salesforce Apex Hours:- Salesforce DXSalesforce Apex Hours:- Salesforce DX
Salesforce Apex Hours:- Salesforce DXAmit Chaudhary
 
AppExchange Tech Enablement June 2017
AppExchange Tech Enablement June 2017AppExchange Tech Enablement June 2017
AppExchange Tech Enablement June 2017Salesforce Partners
 
Continuous integration testing for automation needs and quality of the releases
Continuous integration testing for automation needs and quality of the releasesContinuous integration testing for automation needs and quality of the releases
Continuous integration testing for automation needs and quality of the releasesZado Technologies
 
Summer '13 Developer Preview Webinar
Summer '13 Developer Preview WebinarSummer '13 Developer Preview Webinar
Summer '13 Developer Preview WebinarSalesforce Developers
 
Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environmentYu-Lin Huang
 
Seamless Authentication with Force.com Canvas
Seamless Authentication with Force.com CanvasSeamless Authentication with Force.com Canvas
Seamless Authentication with Force.com CanvasSalesforce Developers
 
Advanced Flow Techniques with Apex and Visualforce
Advanced Flow Techniques with Apex and VisualforceAdvanced Flow Techniques with Apex and Visualforce
Advanced Flow Techniques with Apex and VisualforceSalesforce Developers
 
Build Together And Deliver Continuously With Salesforce DX
Build Together And Deliver Continuously With Salesforce DXBuild Together And Deliver Continuously With Salesforce DX
Build Together And Deliver Continuously With Salesforce DXLynette Lim
 
Building Dynamic UI with Visual Workflow Runtime API
Building Dynamic UI with Visual Workflow Runtime APIBuilding Dynamic UI with Visual Workflow Runtime API
Building Dynamic UI with Visual Workflow Runtime APISalesforce Developers
 
How Force.com developers do more in less time
How Force.com developers do more in less timeHow Force.com developers do more in less time
How Force.com developers do more in less timeAbhinav Gupta
 
Lightning Components Explained
Lightning Components ExplainedLightning Components Explained
Lightning Components ExplainedAtul Gupta(8X)
 

Tendances (20)

Salesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep DiveSalesforce.com API Series: Service Cloud Console Deep Dive
Salesforce.com API Series: Service Cloud Console Deep Dive
 
Apex for Admins: Beyond the Basics
Apex for Admins: Beyond the BasicsApex for Admins: Beyond the Basics
Apex for Admins: Beyond the Basics
 
Restful services with ColdFusion
Restful services with ColdFusionRestful services with ColdFusion
Restful services with ColdFusion
 
Generically Call External Classes from Managed Packages
Generically Call External Classes from Managed PackagesGenerically Call External Classes from Managed Packages
Generically Call External Classes from Managed Packages
 
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
Apex for Admins: Get Started with Apex in 30 Minutes! (part 1)
 
Gowtham_resume
Gowtham_resumeGowtham_resume
Gowtham_resume
 
Salesforce Apex Hours:- Salesforce DX
Salesforce Apex Hours:- Salesforce DXSalesforce Apex Hours:- Salesforce DX
Salesforce Apex Hours:- Salesforce DX
 
Intro to Apex Programmers
Intro to Apex ProgrammersIntro to Apex Programmers
Intro to Apex Programmers
 
AppExchange Tech Enablement June 2017
AppExchange Tech Enablement June 2017AppExchange Tech Enablement June 2017
AppExchange Tech Enablement June 2017
 
Continuous integration testing for automation needs and quality of the releases
Continuous integration testing for automation needs and quality of the releasesContinuous integration testing for automation needs and quality of the releases
Continuous integration testing for automation needs and quality of the releases
 
Summer '13 Developer Preview Webinar
Summer '13 Developer Preview WebinarSummer '13 Developer Preview Webinar
Summer '13 Developer Preview Webinar
 
10 Principles of Apex Testing
10 Principles of Apex Testing10 Principles of Apex Testing
10 Principles of Apex Testing
 
Web based automation testing on Node.js environment
Web based automation testing on Node.js environmentWeb based automation testing on Node.js environment
Web based automation testing on Node.js environment
 
Seamless Authentication with Force.com Canvas
Seamless Authentication with Force.com CanvasSeamless Authentication with Force.com Canvas
Seamless Authentication with Force.com Canvas
 
Advanced Flow Techniques with Apex and Visualforce
Advanced Flow Techniques with Apex and VisualforceAdvanced Flow Techniques with Apex and Visualforce
Advanced Flow Techniques with Apex and Visualforce
 
Build Together And Deliver Continuously With Salesforce DX
Build Together And Deliver Continuously With Salesforce DXBuild Together And Deliver Continuously With Salesforce DX
Build Together And Deliver Continuously With Salesforce DX
 
Building Dynamic UI with Visual Workflow Runtime API
Building Dynamic UI with Visual Workflow Runtime APIBuilding Dynamic UI with Visual Workflow Runtime API
Building Dynamic UI with Visual Workflow Runtime API
 
How Force.com developers do more in less time
How Force.com developers do more in less timeHow Force.com developers do more in less time
How Force.com developers do more in less time
 
Get Started with Salesforce DX!
Get Started with Salesforce DX!Get Started with Salesforce DX!
Get Started with Salesforce DX!
 
Lightning Components Explained
Lightning Components ExplainedLightning Components Explained
Lightning Components Explained
 

Similaire à Javascript-heavy Salesforce Applications

Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptdavejohnson
 
Netserv Software Testing
Netserv Software TestingNetserv Software Testing
Netserv Software Testingsthicks14
 
AWS Summit London 2014 | Deployment Done Right (300)
AWS Summit London 2014 | Deployment Done Right (300)AWS Summit London 2014 | Deployment Done Right (300)
AWS Summit London 2014 | Deployment Done Right (300)Amazon Web Services
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSYoann Gotthilf
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Steve Lange
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxcurwenmichaela
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxhartrobert670
 
RAHUL_Updated( (2)
RAHUL_Updated( (2)RAHUL_Updated( (2)
RAHUL_Updated( (2)Rahul Singh
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSKnoldus Inc.
 
Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...Rachid Kherrazi
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaAgile Testing Alliance
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4Billie Berzinskas
 
Microservice Automated Testing on Kubernetes
Microservice Automated Testing on KubernetesMicroservice Automated Testing on Kubernetes
Microservice Automated Testing on KubernetesShane Galvin
 
Azure DevOps for JavaScript Developers
Azure DevOps for JavaScript DevelopersAzure DevOps for JavaScript Developers
Azure DevOps for JavaScript DevelopersSarah Dutkiewicz
 
Bharath Kesana Selinium Automation Tester
Bharath Kesana Selinium Automation TesterBharath Kesana Selinium Automation Tester
Bharath Kesana Selinium Automation TesterBharath Kesana
 
Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFXTom Mix Petreca
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by ExampleNalin Goonawardana
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day trainingTroy Miles
 

Similaire à Javascript-heavy Salesforce Applications (20)

Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
Netserv Software Testing
Netserv Software TestingNetserv Software Testing
Netserv Software Testing
 
AWS Summit London 2014 | Deployment Done Right (300)
AWS Summit London 2014 | Deployment Done Right (300)AWS Summit London 2014 | Deployment Done Right (300)
AWS Summit London 2014 | Deployment Done Right (300)
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docxBroncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
Broncosbuild.xmlBuilds, tests, and runs the project Broncos..docx
 
RAHUL_Updated( (2)
RAHUL_Updated( (2)RAHUL_Updated( (2)
RAHUL_Updated( (2)
 
RubaDevi_Salesforce
RubaDevi_SalesforceRubaDevi_Salesforce
RubaDevi_Salesforce
 
Unit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
 
iks auf der ElipseCon 2011: Tickling the shoulders of giants
iks auf der ElipseCon 2011: Tickling the shoulders of giantsiks auf der ElipseCon 2011: Tickling the shoulders of giants
iks auf der ElipseCon 2011: Tickling the shoulders of giants
 
Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
 
Microservice Automated Testing on Kubernetes
Microservice Automated Testing on KubernetesMicroservice Automated Testing on Kubernetes
Microservice Automated Testing on Kubernetes
 
Azure DevOps for JavaScript Developers
Azure DevOps for JavaScript DevelopersAzure DevOps for JavaScript Developers
Azure DevOps for JavaScript Developers
 
Bharath Kesana Selinium Automation Tester
Bharath Kesana Selinium Automation TesterBharath Kesana Selinium Automation Tester
Bharath Kesana Selinium Automation Tester
 
Presentation - Course about JavaFX
Presentation - Course about JavaFXPresentation - Course about JavaFX
Presentation - Course about JavaFX
 
Behavior Driven Development by Example
Behavior Driven Development by ExampleBehavior Driven Development by Example
Behavior Driven Development by Example
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day training
 

Plus de 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
 

Plus de 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
 

Dernier

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Dernier (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Javascript-heavy Salesforce Applications

  • 1. JavaScript-heavy Salesforce Applications David Meyer Technical Architect, Appirio dmeyer@appirio.com Andrew Davis Consultant, Appirio adavis@appirio.com
  • 2. The role of JavaScript in Salesforce JS is the ‘last mile’ between Salesforce and users (it already powers much of the Salesforce UI) The relevance of JS continues to grow (Angular, node.js, mongoDB, etc.) Salesforce continues to expand the options for using JavaScript (Lightning Components, Lightning Experience)
  • 3. Justifications: When to go JavaScript-heavy? If you need a highly-customized and responsive UI If you need/want to use JS Frameworks (Angular, Backbone, etc.) To achieve tight integration with other JS tools or web services To bypass Salesforce governor limits To make more complex asynchronous calls than is possible with Apex
  • 4. Sample uses of JavaScript in the AOL Support Console ​  Account info derived from back-end systems ​  Dynamically-sourced customer offers ​ Displaying information from backend systems using browser-based REST APIs
  • 5. ​  Entirely custom JavaScript applications can be included in SFDC ​  … that draw data from external systems ​  … and allow purchases and other actions to be performed on those external systems Sample uses of JavaScript in the AOL Support Console ​ Embedding entirely custom apps inside of Salesforce
  • 6. Salesforce-JavaScript Interaction Behind-the-scenes: Visualforce compiles down to HTML and JavaScript Tools you can use: • Remote Objects (JS data structures that mirror the SFDC database) • Remote Actions (Defined in Apex, invoked from JS using JS callbacks) • Action Methods (Action Functions, Action Support, Action Pollers) • REST web services (Salesforce provides many and lets you write your own too) • Lightning Components (learn more elsewhere) • Tip: exchange complex objects between Apex and JS using JSON.de/serialize() • Tip: overcome cross-org limitations by using JSONP or CORS-enabled services
  • 7. Salesforce-JavaScript Interaction How to pass control and data back and forth
  • 8. JavaScript Concepts Some core ideas to help Salesforce developers
  • 9. JavaScript Concepts Most developers know some JavaScript It’s worth getting to know it well! What we’ll touch on: • Object-oriented JavaScript (properties, methods, protoypes) • Asynchronous JavaScript: (callbacks and promises) • Variable scope in JavaScript (scope, closures, namespacing)
  • 10. Selecting Elements in Visualforce Pages The Id that Visualforce gave them when it renders your pageThe Id you gave to your elements Try this method instead (this also works in CSS)These methods won’t work to select this element
  • 11. Minimize use of global variables Having all of your variables in the global scope is poor practice, makes debugging harder, and there are 950 global variables used in Salesforce that your variable names might conflict withIdeally, create a single global “namespace” object and make your code into its methods and properties
  • 12. Group Related Variables into Objects JSON.parse and JSON.stringify provide an elegant way to pass complex data
  • 14. Promises and the jQuery Deferred Object Deferred objects allow for concise and clear expression of how asynchronous requests should be handled
  • 15. Debugging JavaScript using Chrome DevTools Getting to know the capabilities of Chrome DevTools or Firebug is essential Capabilities of DevTools: • Inspect and modify HTML, CSS, JS, browser data • Monitor network traffic and page rendering timeline • Set breakpoints and step through JS execution • Emulate devices and network speeds • Profile and Audit your JavaScript and page loads DevTools can give you complete visibility into every aspect of your JS
  • 16. Unit Testing JavaScript on Salesforce Setting up a unit testing framework and preparing your code
  • 17. Unit testing JavaScript on Salesforce Why unit test your JavaScript? Setting up a unit testing stack: Node-Karma-Mocha-Chai (locally or in CI) Preparing your code: • Try to move all of your JS into static resources (this can also speed page load) • But {!controllerBindings} need to stay on the Visualforce page • Make sure your code is testable: • Testable methods need to be globally-accessible • Emphasize discrete, independent functions that don’t depend on global values Write unit tests using Mocha and Chai syntax with Sinon for stubs/mocks
  • 18. Sample Unit Testing Stack For installing dependenciesPlatform Test Runner (Creates a web server) Assertion Syntax assert.typeOf(foo, 'string'); assert.equal(foo, 'bar'); assert.lengthOf(foo, 3); Mocks & Stubs var callback = sinon.stub(); callback.withArgs(42).returns(1); callback.withArgs(1).throws("TypeError"); Testing & Reporting (The core test framework) describe('testFn Suite', function () { it('should return true', function () { assert.equal(true, testFn() ); }); });
  • 19. Unit testing stack setup (on your machine) 1.  Install Node.js on your development machine(s). 2.  Grab our code at goo.gl/fMFrm1 (github.com/abd3/DF15-JS-Heavy-Salesforce) 3.  Copy these files from our sample project into yours and customize as needed: a.  /package.json - Node.js will use this to get all the packages you need b.  /karma.conf.js - The configuration file for Karma (which files to test, etc.) c.  /test/* - The actual unit tests used in our sample project 4.  In the root of your development directory (where package.json is installed) run the following one-time installation command from the command line: npm install 5.  Run the following code from the command-line every time you want to start the karma test runner: ./node_modules/karma/bin/karma start karma.conf.js 6.  autowatch = true in our sample configuration file, so Karma will re-run all the unit tests each time you save a change to one of the files being tested.
  • 20. Unit Test FilesSalesforce Files Anatomy of a JavaScript Unit Test Salesforce Files Unit Test Files Similar Unit Tests can be Grouped Salesforce Files Setup & Tear-down steps Actual Unit Tests
  • 21. Setup & Tear-down steps Setup & Tear-down steps Anatomy of a JavaScript Unit Test
  • 22. Actual Unit Tests Anatomy of a JavaScript Unit Test
  • 23. Karma’s unit testing interface Command-line or web-based Browser-based test runner The command-line test runner auto-runs when files change
  • 24. Karma’s code coverage report (karma-junit-reporter style) This shows aggregate and line-by-line unit test coverage on the project Aggregate code-coverage for the project Line-by-line code coverage
  • 25. Unit testing stack (for Continuous Integration) ​ General guidelines for including JS unit testing in your CI builds: •  Set up a separate build step for the JS unit testing •  Install the nodejs plugin for Jenkins and specify your version of node & npm •  The build step consists simply of running this shell command: npm install node_modules/karma/bin/karma start karma.conf.js --single-run •  The build step will succeed or fail based on the results of that command •  This will also output some reports in the /reports folder that can be ingested to report on code coverage, code quality, etc. if you’re using code quality tools
  • 26. ​  Build step for JS code quality analysis in SonarQube JavaScript Unit Testing as a Continuous Deployment Step ​ JS unit testing can be one step in a CI/CD setup ​  Build step to run JavaScript unit tests Jenkins build step to deploy to a QA org. This also runs Apex unit tests
  • 27. Karma outputs, displayed in SonarQube Karma’s unit testing output can be ingested and displayed in other products
  • 28. Questions & Answers Grab the code at goo.gl/fMFrm1 (https://github.com/abd3/DF15-JS-Heavy-Salesforce)
  • 29. Share Your Feedback, and Win a GoPro! 3 Earn a GoPro prize entry for each completed survey Tap the bell to take a survey2Enroll in a session1
  • 31. Salesforce - JavaScript Integration Methods Note that you can mix and match any combination of these as needed Action Methods JavaScript Remoting Remote Objects Salesforce REST API Require Controller Code yes yes no no Require Visualforce yes yes yes no Have their own Governor Limits no no no yes Main Benefit Call static or instance methods while maintaining controller state Call static Apex methods quickly and efficiently Create a JS version of Salesforce object with CRUD access Perform Salesforce actions and modify data from external apps Main Disadvantage Submits form data; slower Limited to static methods Can’t execute custom Apex from VF this way