Javascript and Remote Objects on Force.com Winter 15

19
A Miscellany of Things Force.com Peter Chittum @pchittum github.com/pchittum slideshare.com/ chittum

description

A round up of the state of Javascript on Force.com now that remote objects are about to go GA on Force.com in Winter 15. There are now four great options for invoking Javascript on your Visualforce page. Learn what they are, and more importantly why you need all of them, and when to use each one. Delivered at Salesforce Developer Group North on 18 September, 2014.

Transcript of Javascript and Remote Objects on Force.com Winter 15

Page 1: Javascript and Remote Objects on Force.com Winter 15

A Miscellany of Things Force.com

Peter [email protected]/pchittumslideshare.com/chittum

Page 2: Javascript and Remote Objects on Force.com Winter 15

Safe HarborSafe 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 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, 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, 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-K for the most recent fiscal quarter ended July 31, 2011. This document and others 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 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.

Page 3: Javascript and Remote Objects on Force.com Winter 15

What’s On?

Javascript on Visualforce

Remote Objects

RevealJS

Page 4: Javascript and Remote Objects on Force.com Winter 15

JS Options for Visualforce

Tag: apex:actionFunction

API Calls

@RemoteAction Apex Methods

Remote Object

Page 5: Javascript and Remote Objects on Force.com Winter 15

The Old Way

actionFunction Pros– Easy and Declarative

API Pros– Use of idiomatic JS

– No ViewState Overhead

– Higher data size limits

– Simple REST access via ForceTK

actionFunction Cons– ViewState and VF

Postback overhead

API Cons– Burning API limit usage

Page 6: Javascript and Remote Objects on Force.com Winter 15

The Newer Way

@RemoteAction Apex Method– Stateless

– More idiomatic (uses callback)

– Simplified on client side with RemoteTK library

Page 7: Javascript and Remote Objects on Force.com Winter 15

The New Way

Remote Object– Like Standard Controller and Remote methods got

together and had a baby

– Declared via markup

– No Apex, no required tests, just Javascript code

– Support for basic CRUD operations

Page 8: Javascript and Remote Objects on Force.com Winter 15

The Three Musketeers

Remote Object– First choice for basic CRUD

@RemoteAction Apex Method– Move complexity to server and transaction control

API– Larger data (binary files)

Page 9: Javascript and Remote Objects on Force.com Winter 15

What’s On?

Javascript on Visualforce

Remote Objects

RevealJS

Page 10: Javascript and Remote Objects on Force.com Winter 15

More on Remote Object

GA in Winter 15!

CRUD: Create, Retrieve, Update, Upsert, Delete

Optional page-specific JS namespace

Maps long Salesforce field names to JS-friendly names

Page 11: Javascript and Remote Objects on Force.com Winter 15

Remote Object: Declaration

<apex:remoteObjects >

<apex:remoteObjectModel name="pcprerel__Damage_Report__c”

fields="Id,Name" jsShorthand="DamageReport">

<apex:remoteObjectField name="pcprerel__Merchandise__c"

jsShorthand="merchId"/>

<apex:remoteObjectField name="pcprerel__Type__c"

jsShorthand="type"/>

...

</apex:remoteObjectModel>

</apex:remoteObjects>

Page 12: Javascript and Remote Objects on Force.com Winter 15

Remote Object: Create JS Object

var dr = new SObjectModel.DamageReport({

"merchId" : "{!Merchandise__c.Id}",

"type" : "Accident",

"description" : $('#ta-description').val()

});

Page 13: Javascript and Remote Objects on Force.com Winter 15

Remote Object: Invoke DML

dr.create(function(err, result, event){

//debug with event to find out transaction status

if (err) {

console.log(err);

//do stuff with err

} else {

//use result

$('#test-display').text('Damage Report Id: '+result[0] );

}

});

Page 14: Javascript and Remote Objects on Force.com Winter 15

Demo

Page 15: Javascript and Remote Objects on Force.com Winter 15

Other Features

Overriding of CRUD calls

Own set of limits (i.e. max 100 rows for retrieve)

Use rendered VF attribute to block generation of JS

Page 16: Javascript and Remote Objects on Force.com Winter 15

What’s On?

Javascript on Visualforce

Remote Objects

RevealJS

Page 17: Javascript and Remote Objects on Force.com Winter 15

RevealJS

Javascript library

Creating pure HTML presentations

Opensource at https://github.com/hakimel/reveal.js/

Cloud hosted at http://slid.es

Page 18: Javascript and Remote Objects on Force.com Winter 15

Demo

Watch this play list to see RevealJS on Force.comhttp://www.youtube.com/playlist?list=PLkZK3G49sP2xE-yzEMvVJhbHmGMMDOkLz

Page 19: Javascript and Remote Objects on Force.com Winter 15

Thank You