SlideShare a Scribd company logo
1 of 36
Download to read offline
Force.com Webinar:
                                       Advanced Visualforce

                                       Eric Wilson
                                       Director, Product Management
                                       UI Platforms




Join the conversation: #forcewebinar
Agenda
      1. Assumptions
      2. Your Frienemy: View State
      3. Managing View State
      4. Asynchronous Apex




Join the conversation: #forcewebinar
Assumptions




Join the conversation: #forcewebinar
This Advanced Webinar Assumes...


      ...you have used Visualforce and are comfortable with it.


      ...you have used Apex and are comfortable writing it.


      ...you understand HTML, JavaScript, and AJAX concepts.




Join the conversation: #forcewebinar
Your Frienemy:
                                         View State




Join the conversation: #forcewebinar
Q: What is View State?
      A: An encrypted, hidden <input> field on a Visualforce page that
      keeps track of Apex controller state & Visualforce page state
      between server requests. This field is only generated when
      there is an <apex:form> tag present on a page.




Join the conversation: #forcewebinar
Visualforce Lifecycle
   A


                                                HTTP GET

                                                           A. URL Requested
                               E                           B. Apex Controller Instantiated on Server
                           HTTP POST
                                                           C. Controller State Serialized & Encrypted to View State

                                                           D. Page Markup Sent to Browser & Rendered
    D
                                                     B     E. View State Decrypted & Deserialized (for Postbacks)




           <input type="hidden" value="..."/>    C


Join the conversation: #forcewebinar
View State: Your Frienemy



                   Why it’s Great :-)               Why it’s Not So Great :-(
      • Automatically keeps track of field    • Can be bulky, affecting performance.
        values for you.                       • It has size limitations.
      • Allows for easy AJAX functionality.   • Doesn’t allow for complex AJAX
      • Provides easy way to re-render page    functionality.
        components.




Join the conversation: #forcewebinar
View State is Required for...
   <apex:action*>
   <apex:command*>
   <apex:inlineEditSupport>
   <apex:input*>
   <apex:select*>




Join the conversation: #forcewebinar
Managing View State




Join the conversation: #forcewebinar
How Can I Manage My View State?
   A. Reduce Number of Components
   B. Use the transient Keyword
   C. Use JavaScript Remoting
   D. Use the Streaming API




Join the conversation: #forcewebinar
Option A: Reduce Number of Components

          <apex:outputPanel layout="inline"...>   <span...>


          <apex:outputPanel layout="block"...>    <div...>


          <apex:panelGrid...>                     <table...>


          <apex:outputLink...>                    <a...>


          <apex:outputText styleClass="..."...>   <span...>




Join the conversation: #forcewebinar
Option B: Use the transient Keyword


      public with sharing class EditClientController {

      	           public               Contact         client              {   get;   set;   }
      	 transient public               List<Contact>   connections         {   get;   set;   }
      	 transient public               List<Account>   previousEmployers   {   get;   set;   }
      	 transient public               Set<String>     hashTags            {   get;   set;   }

            ...

      }




Join the conversation: #forcewebinar
Option B: Use the transient Keyword

             BEFORE
             AFTER




                                         58%




Join the conversation: #forcewebinar
Option C: Use JavaScript Remoting
   Q: What is JavaScript Remoting?
   A: Stateless way to call Apex controller methods from JavaScript.




Join the conversation: #forcewebinar
Option C: Use JavaScript Remoting



                            Find Customer:




                                       <apex:actionFunction ... />
                                        <apex:actionRegion ... />
                                            JavaScript Remoting
                                       <apex:actionSupport ... />




Join the conversation: #forcewebinar
JavaScript Remoting Lifecycle




                                       JS Function

                                       Apex Method
                                                     Client-side

                                       JS Callback   Server-side




Join the conversation: #forcewebinar
JS Function


                                       Apex Method


                                       JS Callback




Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The Page

 <apex:page controller="FindCustomerController">

        <input id="searchField" type="text" placeholder="Enter Last Name"/>
        <button onclick="handleButtonClick();">Search</button>

        <table>
            <tbody id="results"></tbody>
        </table>
                                                                      JS Function

 </apex:page>                                                         Apex Method


                                                                      JS Callback




Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The Page

 <apex:page controller="FindCustomerController">

        <input id="searchField" type="text" placeholder="Enter Last Name"/>
        <button onclick="handleButtonClick();">Search</button>

        <table>
            <tbody id="results"></tbody>
        </table>
                                                                      JS Function

 </apex:page>                                                         Apex Method


                                                                      JS Callback




Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The JavaScript




     function handleButtonClick() {
         var searchTerm = document.getElementById("searchField").value;
         FindCustomerController.doSearch(searchTerm, renderResults);
     }

                                                                    JS Function


                                                                    Apex Method


                                                                    JS Callback




Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The JavaScript




     function handleButtonClick() {
         var searchTerm = document.getElementById("searchField").value;
         FindCustomerController.doSearch(searchTerm, renderResults);
     }
                           Apex Class   Apex Method   Apex Method Parameter   JS Callback Function


                                                                                                     JS Function


                                                                                                     Apex Method


                                                                                                     JS Callback




Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The Apex Class
     public with sharing class FindCustomerController {

           @RemoteAction
           public static List<Contact> doSearch(String customerLastName) {
               customerLastName = '%' + customerLastName + '%';
               return [
                   SELECT id, FirstName, LastName
                   FROM Contact
                   WHERE LastName LIKE :customerLastName
                   LIMIT 200
               ];                                                      JS Function

           }                                                           Apex Method


                                                                            JS Callback
     }


Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The Apex Class
     public with sharing class FindCustomerController {

           @RemoteAction
           public static List<Contact> doSearch(String customerLastName) {
               customerLastName = '%' + customerLastName + '%';
               return [
                   SELECT id, FirstName, LastName
                   FROM Contact
                   WHERE LastName LIKE :customerLastName
                   LIMIT 200
               ];                                                      JS Function

           }                                                           Apex Method


                                                                            JS Callback
     }


Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The Callback


   function renderResults(results, event) {
       var container = document.getElementById("results"),
                html = [];
       for (var i=0, j=results.length; i<j; i++) {
           html.push("<tr><td>");
           html.push(results[i].LastName + ", " + results[i].FirstName);
           html.push("</td></tr>");
       }
       container.innerHTML = html.join("");                         JS Function

   }                                                                Apex Method


                                                                         JS Callback




Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The Results




                                                JS Function


                                                Apex Method


                                                JS Callback




Join the conversation: #forcewebinar
Option C: JavaScript Remoting: The Results




          BEFORE                                AFTER
           234ms                                152ms
                                                 35%




Join the conversation: #forcewebinar
Option D: Use the Streaming API
   Q: What is the Streaming API?
   A: A highly performant way to get near-real-time updates from
      a Salesforce instance without polling.




Join the conversation: #forcewebinar
Option D: Use the Streaming API
    BEFORE
<apex:page controller="NewAccountsController">
<apex:form>

     <apex:actionPoller action="{!find}" rerender="wrapper" interval="15"/>
     <h1>Streaming API Example</h1>
     <h2>New Accounts</h2>
     <apex:outputPanel id="wrapper"></apex:outputPanel>

</apex:form>
</apex:page>




Join the conversation: #forcewebinar
Option D: Use the Streaming API
    AFTER
<apex:page controller="NewAccountsController">

     <apex:includeScript value="..."/> <!-- 4 js files needed -->

     <h1>Streaming API Example</h1>
     <h2>New Accounts</h2>
     <div id="wrapper"></div>
     <script>... $.cometd.init(...) $.cometd.subscribe(...) ...</script>

</apex:page>




Join the conversation: #forcewebinar
Option D: Use the Streaming API: Steps
   Determine Your SOQL Query
   Create a PushTopic Record
   Include Necessary JavaScript Libraries on Visualforce Page
   Call cometd’s init(...) and subscribe(...) Functions (Inline JS)
   Watch Magic Happen




Join the conversation: #forcewebinar
Asynchronous Apex




Join the conversation: #forcewebinar
Asynchronous Apex
       public with sharing class SendInvoiceController{

             @RemoteAction
             public static String requestAllInvoices(String customerId) {
                 sendAllInvoices(customerId);
                 return('All invoices have been requested.');
             }

             @future
             private static void sendAllInvoices(String customerId) {
                 EmailHelper.emailCustomerInvoices(customerId);
             }

       }


Join the conversation: #forcewebinar
Survey
          Your feedback is crucial to the success of our webinar programs.
                                        Thank you!

                   http://bit.ly/advancedvfsurvey




Join the conversation: #forcewebinar
Q&A

                                       Eric Wilson
                                       Director, Product Management
                                       UI Platforms




Join the conversation: #forcewebinar
Upcoming Events

                     December 11, 2012
                     AppExchange for Developers Webinar
                     http://bit.ly/XnFERP


                     December 12, 2012
                     Apex CodeTalk Live Q&A
                     http://bit.ly/apexct-vf

  Check out the Developer Force calendar for upcoming local events such as meetups,
  workshops, and user group meetings: http://developer.force.com/Calendar


Join the conversation: #forcewebinar

More Related Content

What's hot

What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFMax Katz
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenThorsten Kamann
 
When Smalltalk Meets the Web
When Smalltalk Meets the WebWhen Smalltalk Meets the Web
When Smalltalk Meets the WebESUG
 
Visualforce: Using ActionFunction vs. RemoteAction
Visualforce: Using ActionFunction vs. RemoteActionVisualforce: Using ActionFunction vs. RemoteAction
Visualforce: Using ActionFunction vs. RemoteActionSalesforce Developers
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014cagataycivici
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012cagataycivici
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Arun Gupta
 
Visualforce: Using JavaScript Remoting for Apex Controllers
Visualforce: Using JavaScript Remoting for Apex ControllersVisualforce: Using JavaScript Remoting for Apex Controllers
Visualforce: Using JavaScript Remoting for Apex Controllersprabhat gangwar
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialYi-Ting Cheng
 
IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.
IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.
IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.Dacartec Servicios Informáticos
 
Difference between-action-support
Difference between-action-supportDifference between-action-support
Difference between-action-supportAbdul Mujeeb Shaik
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011David Carr
 
Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Max Pronko
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with StripesSamuel Santos
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataStacy London
 
Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3quyong2000
 

What's hot (20)

What You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSFWhat You Need To Build Cool Enterprise Applications With JSF
What You Need To Build Cool Enterprise Applications With JSF
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
 
When Smalltalk Meets the Web
When Smalltalk Meets the WebWhen Smalltalk Meets the Web
When Smalltalk Meets the Web
 
Visualforce: Using ActionFunction vs. RemoteAction
Visualforce: Using ActionFunction vs. RemoteActionVisualforce: Using ActionFunction vs. RemoteAction
Visualforce: Using ActionFunction vs. RemoteAction
 
PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014PrimeTime JSF with PrimeFaces - Dec 2014
PrimeTime JSF with PrimeFaces - Dec 2014
 
Sightly - Part 2
Sightly - Part 2Sightly - Part 2
Sightly - Part 2
 
How we rest
How we restHow we rest
How we rest
 
Primefaces Confess 2012
Primefaces Confess 2012Primefaces Confess 2012
Primefaces Confess 2012
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
Visualforce: Using JavaScript Remoting for Apex Controllers
Visualforce: Using JavaScript Remoting for Apex ControllersVisualforce: Using JavaScript Remoting for Apex Controllers
Visualforce: Using JavaScript Remoting for Apex Controllers
 
OSDC 2009 Rails Turtorial
OSDC 2009 Rails TurtorialOSDC 2009 Rails Turtorial
OSDC 2009 Rails Turtorial
 
IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.
IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.
IBM WebSphere Portal Integrator for SAP - Escenario de ejemplo.
 
Difference between-action-support
Difference between-action-supportDifference between-action-support
Difference between-action-support
 
Stripes Framework
Stripes FrameworkStripes Framework
Stripes Framework
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
 
CakePHP
CakePHPCakePHP
CakePHP
 
Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
 
Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3Alfresco Tech Talk Live-Web Editor - 3.3
Alfresco Tech Talk Live-Web Editor - 3.3
 

Similar to Advanced Visualforce Webinar

Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface
 
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
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentChui-Wen Chiu
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Arun Gupta
 
RichFaces: rich:* component library
RichFaces: rich:* component libraryRichFaces: rich:* component library
RichFaces: rich:* component libraryMax Katz
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Arun Gupta
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09Daniel Bryant
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkara JUG
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008Joe Walker
 
What's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewWhat's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewMaxim Veksler
 
Ajax Under The Hood
Ajax Under The HoodAjax Under The Hood
Ajax Under The HoodWO Community
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Againjonknapp
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4Naga Muruga
 
Introduction to RichFaces
Introduction to RichFacesIntroduction to RichFaces
Introduction to RichFacesMax Katz
 
Javascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web AppsJavascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web Appsdnelson-cs
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component BehaviorsAndy Schwartz
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
Modular Web Applications With Netzke
Modular Web Applications With NetzkeModular Web Applications With Netzke
Modular Web Applications With Netzkenetzke
 

Similar to Advanced Visualforce Webinar (20)

Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
RichFaces: rich:* component library
RichFaces: rich:* component libraryRichFaces: rich:* component library
RichFaces: rich:* component library
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
 
Async
AsyncAsync
Async
 
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09L2 Web App Development Guest Lecture At University of Surrey 20/11/09
L2 Web App Development Guest Lecture At University of Surrey 20/11/09
 
AnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFacesAnkaraJUG Kasım 2012 - PrimeFaces
AnkaraJUG Kasım 2012 - PrimeFaces
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008
 
What's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overviewWhat's new in Rails 5 - API Mode & Action Cable overview
What's new in Rails 5 - API Mode & Action Cable overview
 
Ajax Under The Hood
Ajax Under The HoodAjax Under The Hood
Ajax Under The Hood
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4
 
Introduction to RichFaces
Introduction to RichFacesIntroduction to RichFaces
Introduction to RichFaces
 
Javascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web AppsJavascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web Apps
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
JSF 2.0 Preview
JSF 2.0 PreviewJSF 2.0 Preview
JSF 2.0 Preview
 
Modular Web Applications With Netzke
Modular Web Applications With NetzkeModular Web Applications With Netzke
Modular Web Applications With Netzke
 

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
 

Advanced Visualforce Webinar

  • 1. Force.com Webinar: Advanced Visualforce Eric Wilson Director, Product Management UI Platforms Join the conversation: #forcewebinar
  • 2. Agenda 1. Assumptions 2. Your Frienemy: View State 3. Managing View State 4. Asynchronous Apex Join the conversation: #forcewebinar
  • 4. This Advanced Webinar Assumes... ...you have used Visualforce and are comfortable with it. ...you have used Apex and are comfortable writing it. ...you understand HTML, JavaScript, and AJAX concepts. Join the conversation: #forcewebinar
  • 5. Your Frienemy: View State Join the conversation: #forcewebinar
  • 6. Q: What is View State? A: An encrypted, hidden <input> field on a Visualforce page that keeps track of Apex controller state & Visualforce page state between server requests. This field is only generated when there is an <apex:form> tag present on a page. Join the conversation: #forcewebinar
  • 7. Visualforce Lifecycle A HTTP GET A. URL Requested E B. Apex Controller Instantiated on Server HTTP POST C. Controller State Serialized & Encrypted to View State D. Page Markup Sent to Browser & Rendered D B E. View State Decrypted & Deserialized (for Postbacks) <input type="hidden" value="..."/> C Join the conversation: #forcewebinar
  • 8. View State: Your Frienemy Why it’s Great :-) Why it’s Not So Great :-( • Automatically keeps track of field • Can be bulky, affecting performance. values for you. • It has size limitations. • Allows for easy AJAX functionality. • Doesn’t allow for complex AJAX • Provides easy way to re-render page functionality. components. Join the conversation: #forcewebinar
  • 9. View State is Required for... <apex:action*> <apex:command*> <apex:inlineEditSupport> <apex:input*> <apex:select*> Join the conversation: #forcewebinar
  • 10. Managing View State Join the conversation: #forcewebinar
  • 11. How Can I Manage My View State? A. Reduce Number of Components B. Use the transient Keyword C. Use JavaScript Remoting D. Use the Streaming API Join the conversation: #forcewebinar
  • 12. Option A: Reduce Number of Components <apex:outputPanel layout="inline"...> <span...> <apex:outputPanel layout="block"...> <div...> <apex:panelGrid...> <table...> <apex:outputLink...> <a...> <apex:outputText styleClass="..."...> <span...> Join the conversation: #forcewebinar
  • 13. Option B: Use the transient Keyword public with sharing class EditClientController { public Contact client { get; set; } transient public List<Contact> connections { get; set; } transient public List<Account> previousEmployers { get; set; } transient public Set<String> hashTags { get; set; } ... } Join the conversation: #forcewebinar
  • 14. Option B: Use the transient Keyword BEFORE AFTER 58% Join the conversation: #forcewebinar
  • 15. Option C: Use JavaScript Remoting Q: What is JavaScript Remoting? A: Stateless way to call Apex controller methods from JavaScript. Join the conversation: #forcewebinar
  • 16. Option C: Use JavaScript Remoting Find Customer: <apex:actionFunction ... /> <apex:actionRegion ... /> JavaScript Remoting <apex:actionSupport ... /> Join the conversation: #forcewebinar
  • 17. JavaScript Remoting Lifecycle JS Function Apex Method Client-side JS Callback Server-side Join the conversation: #forcewebinar
  • 18. JS Function Apex Method JS Callback Join the conversation: #forcewebinar
  • 19. Option C: JavaScript Remoting: The Page <apex:page controller="FindCustomerController"> <input id="searchField" type="text" placeholder="Enter Last Name"/> <button onclick="handleButtonClick();">Search</button> <table> <tbody id="results"></tbody> </table> JS Function </apex:page> Apex Method JS Callback Join the conversation: #forcewebinar
  • 20. Option C: JavaScript Remoting: The Page <apex:page controller="FindCustomerController"> <input id="searchField" type="text" placeholder="Enter Last Name"/> <button onclick="handleButtonClick();">Search</button> <table> <tbody id="results"></tbody> </table> JS Function </apex:page> Apex Method JS Callback Join the conversation: #forcewebinar
  • 21. Option C: JavaScript Remoting: The JavaScript function handleButtonClick() { var searchTerm = document.getElementById("searchField").value; FindCustomerController.doSearch(searchTerm, renderResults); } JS Function Apex Method JS Callback Join the conversation: #forcewebinar
  • 22. Option C: JavaScript Remoting: The JavaScript function handleButtonClick() { var searchTerm = document.getElementById("searchField").value; FindCustomerController.doSearch(searchTerm, renderResults); } Apex Class Apex Method Apex Method Parameter JS Callback Function JS Function Apex Method JS Callback Join the conversation: #forcewebinar
  • 23. Option C: JavaScript Remoting: The Apex Class public with sharing class FindCustomerController { @RemoteAction public static List<Contact> doSearch(String customerLastName) { customerLastName = '%' + customerLastName + '%'; return [ SELECT id, FirstName, LastName FROM Contact WHERE LastName LIKE :customerLastName LIMIT 200 ]; JS Function } Apex Method JS Callback } Join the conversation: #forcewebinar
  • 24. Option C: JavaScript Remoting: The Apex Class public with sharing class FindCustomerController { @RemoteAction public static List<Contact> doSearch(String customerLastName) { customerLastName = '%' + customerLastName + '%'; return [ SELECT id, FirstName, LastName FROM Contact WHERE LastName LIKE :customerLastName LIMIT 200 ]; JS Function } Apex Method JS Callback } Join the conversation: #forcewebinar
  • 25. Option C: JavaScript Remoting: The Callback function renderResults(results, event) { var container = document.getElementById("results"), html = []; for (var i=0, j=results.length; i<j; i++) { html.push("<tr><td>"); html.push(results[i].LastName + ", " + results[i].FirstName); html.push("</td></tr>"); } container.innerHTML = html.join(""); JS Function } Apex Method JS Callback Join the conversation: #forcewebinar
  • 26. Option C: JavaScript Remoting: The Results JS Function Apex Method JS Callback Join the conversation: #forcewebinar
  • 27. Option C: JavaScript Remoting: The Results BEFORE AFTER 234ms 152ms 35% Join the conversation: #forcewebinar
  • 28. Option D: Use the Streaming API Q: What is the Streaming API? A: A highly performant way to get near-real-time updates from a Salesforce instance without polling. Join the conversation: #forcewebinar
  • 29. Option D: Use the Streaming API BEFORE <apex:page controller="NewAccountsController"> <apex:form> <apex:actionPoller action="{!find}" rerender="wrapper" interval="15"/> <h1>Streaming API Example</h1> <h2>New Accounts</h2> <apex:outputPanel id="wrapper"></apex:outputPanel> </apex:form> </apex:page> Join the conversation: #forcewebinar
  • 30. Option D: Use the Streaming API AFTER <apex:page controller="NewAccountsController"> <apex:includeScript value="..."/> <!-- 4 js files needed --> <h1>Streaming API Example</h1> <h2>New Accounts</h2> <div id="wrapper"></div> <script>... $.cometd.init(...) $.cometd.subscribe(...) ...</script> </apex:page> Join the conversation: #forcewebinar
  • 31. Option D: Use the Streaming API: Steps Determine Your SOQL Query Create a PushTopic Record Include Necessary JavaScript Libraries on Visualforce Page Call cometd’s init(...) and subscribe(...) Functions (Inline JS) Watch Magic Happen Join the conversation: #forcewebinar
  • 32. Asynchronous Apex Join the conversation: #forcewebinar
  • 33. Asynchronous Apex public with sharing class SendInvoiceController{ @RemoteAction public static String requestAllInvoices(String customerId) { sendAllInvoices(customerId); return('All invoices have been requested.'); } @future private static void sendAllInvoices(String customerId) { EmailHelper.emailCustomerInvoices(customerId); } } Join the conversation: #forcewebinar
  • 34. Survey Your feedback is crucial to the success of our webinar programs. Thank you! http://bit.ly/advancedvfsurvey Join the conversation: #forcewebinar
  • 35. Q&A Eric Wilson Director, Product Management UI Platforms Join the conversation: #forcewebinar
  • 36. Upcoming Events December 11, 2012 AppExchange for Developers Webinar http://bit.ly/XnFERP December 12, 2012 Apex CodeTalk Live Q&A http://bit.ly/apexct-vf Check out the Developer Force calendar for upcoming local events such as meetups, workshops, and user group meetings: http://developer.force.com/Calendar Join the conversation: #forcewebinar