Upload
salesforce-developers
View
1.140
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
Visualforce:
Using ActionFunction vs. RemoteAction
Tom Patros, Red Argyle, Principal
@tompatros
Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties
materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results
expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be
deemed forward-looking, including any projections of product or service availability, subscriber growth, earnings, revenues, or other
financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any
statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new
functionality for our service, new products and services, our new business model, our past operating losses, possible fluctuations in our
operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of
intellectual property and other litigation, risks associated with possible mergers and acquisitions, the immature market in which we
operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new
releases of our service and successful customer deployment, our limited history reselling non-salesforce.com products, and utilization
and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com,
inc. is included in our annual report on Form 10-Q for the most recent fiscal quarter ended July 31, 2012. This documents and others
containing important disclosures are available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently
available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based
upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-
looking statements.
All About Red Argyle
Force.com 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
www.redargyle.com
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.
Our demo app
“This vs. That”
Battle__c object
Combatant__c object
<apex:actionFunction>
Standard Visualforce component.
Exposes Apex controller method as Javascript function.
Accepts String parameters.
Interacts with standard Visualforce features (rerender, status).
<apex:actionFunction action="{!saveBattle}" name="saveBattleJS" rerender="battleBlock" status="saveStatus">
<apex:param name="p_winnerSFID" assignTo="{!winnerSFID}" value="" />
</apex:actionFunction>
ActionFunction demo
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. ActionFunction’s param component passes SFID to
controller.
5. status and rerender settings handle ajax updates.
@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);
RemoteAction demo
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.
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).
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.
Single-page app demo
What just happened?
Minimal VF page.
All Apex methods are @RemoteActions.
App logic and UI rendering in JS.
jQuery + Bootstrap + Underscore + Handlebars + Backbone!
RemoteAction doesn’t get in the way of other JS libraries.
Resources
ActionFunction Docs - http://bit.ly/O509ze
RemoteAction Docs - http://bit.ly/l1du9P
Demo App - https://github.com/tompatros/tp-df12-demo
Two VF Pages (AF & JS Remoting) - http://bit.ly/yFjd2M
Developing Apps with jQuery - http://bit.ly/NqzHcI
Salesforce Javascript Remoting - http://bit.ly/Lnr6wM