Visualforce: Using ActionFunction vs. RemoteAction

  • View

  • Download

Embed Size (px)



Text of Visualforce: Using ActionFunction vs. RemoteAction

  • 1. Visualforce: Using ActionFunction vs. RemoteActionTom Patros, Red Argyle, Principal@tompatros
  • 2. Safe Harbor Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services. The risks and uncertainties referred to above include but are not limited to risks associated with developing and delivering new functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of intellectual property and other litigation, risks associated with possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our limited history reselling products, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of, inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended July 31, 2012. This documents and others containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site. Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available., inc. assumes no obligation and does not intend to update these forward- looking statements.
  • 3. All About Red Argyle development and consulting shop in Upstate New York. We specialize in custom apps, portal development, product development and admin support. Founded by Tom Patros (@tompatros) in 2010 Partnership with Garry Polmateer (@darthgarry) in 2011 Staff in Buffalo, Rochester, Albany and Corning, NY
  • 4. Goals for this session Compare ActionFunction and RemoteAction. Build a basic single-page web app backed by RemoteActions. Integrate our web app with jQuery, Bootstrap and Backbone. Answer questions and solve problems.
  • 5. Our demo app This vs. That Battle__c object Combatant__c object
  • 6. Standard Visualforce component. Exposes Apex controller method as Javascript function. Accepts String parameters. Interacts with standard Visualforce features (rerender, status).
  • 7. ActionFunction demo
  • 8. What just happened? 1. ActionFunction saveBattleJS exposes saveBattle Apex method. 2. saveBattleJS is wrapped in winnerClick with confirm call. 3. Onclick events of both buttons invoke winnerClick, passing Combatant__c SFID as the winner. 4. ActionFunctions param component passes SFID to controller. 5. status and rerender settings handle ajax updates.
  • 9. @RemoteAction Apex method annotation (a la @future). Exposes Apex controller method to Javascript. Invoked as MyController.myMethod() Accepts parameters (primitives, collections, sObjects, more...). Invocation provides callback with status and returned values. Visualforce.remoting.Manager.invokeAction(name, params, callback);
  • 10. RemoteAction demo
  • 11. What just happened? 1. saveBattle and loadCombatantOptions are @RemoteActions. 2. loadCombantantOptions is invoked during jQuery document.ready event. 3. saveBattle is invoked when buttons are clicked, passing JS object representing Battle__c object. 4. UI refreshes instantly, assuming successful insert of Battle__c.
  • 12. ActionFunction usage, pros and cons Ideal for client-side processing before sending to Apex. (confirm / validate / calculate / repeating) Faster to wire up for basic use cases. Access to built-in VF capabilities. String-only parameters. Callbacks are trickier (onstop / oncomplete).
  • 13. RemoteAction usage, pros and cons Ideal for custom app with flexible, responsive UI. JS-centric approach (invoke, callback). Parameters. Performance (no viewstate = 2-3x faster). Implementation is trickier.
  • 14. Single-page app demo
  • 15. What just happened? Minimal VF page. All Apex methods are @RemoteActions. App logic and UI rendering in JS. jQuery + Bootstrap + Underscore + Handlebars + Backbone! RemoteAction doesnt get in the way of other JS libraries.
  • 16. Resources ActionFunction Docs - RemoteAction Docs - Demo App - Two VF Pages (AF & JS Remoting) - Developing Apps with jQuery - Salesforce Javascript Remoting -