24
S1 Publisher – VF Edition 25 April, 2014

S1 and Visualforce Publisher Actions

Embed Size (px)

DESCRIPTION

S1 Coding Dojo Presentation from 25 April, 2014

Citation preview

Page 1: S1 and Visualforce Publisher Actions

S1 Publisher – VF Edition25 April, 2014

Page 2: S1 and Visualforce Publisher Actions

Peter ChittumDeveloper Evangelist@pchittum

Page 3: S1 and Visualforce Publisher Actions

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 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 any litigation, risks associated with completed and any 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 year and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These 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.

Page 4: S1 and Visualforce Publisher Actions

Visualforce

Page 5: S1 and Visualforce Publisher Actions

Framework

Server-side compiled web pages– (Think PHP, JSP, etc.)

Easily create salesforce UI

Standard-compliant

Can Interact With Apex for Custom Logic

Page 6: S1 and Visualforce Publisher Actions

Device Access Through Web APIs

Audio/Video Capture

Geolocation

Accelerometer

Page 7: S1 and Visualforce Publisher Actions

Visualforce Tags

<apex:page docType=“html-5.0” />

<apex:input type=“email”/>

<apex:pageBlockSection collapsible=“false” />

Page 8: S1 and Visualforce Publisher Actions

Styling for Visualforce in S1

Salesforce1 Styleguidesfdc-styleguide.herokuapp.com/

OneStarter jQuery plugingithub.com/joshbirk/onestarter

Page 9: S1 and Visualforce Publisher Actions

Hashed information block to track server side transports

Viewstate

Page 10: S1 and Visualforce Publisher Actions

Apex Form

Required for standard salesforce post

Incurs Viewstate Overhead

<apex:form> …</apex:form

aspdoifuapknva894372h4ofincao98vh0q938hfoqiwnbdco8q73h0o9fqubovilbodfubqo3e8ufbw

Page 11: S1 and Visualforce Publisher Actions

Interacting with the Platform

Apex Controller Instance Method

Apex Controller Static Remoting Method

REST API

Visualforce Remote Object

Page 12: S1 and Visualforce Publisher Actions

Apex Instance Method

Use with apex:actionFunction to access via Javascript

ActionFunction requires ViewState

Reduce ViewState with Transient and Static

Page 13: S1 and Visualforce Publisher Actions

Apex Remote Action

Static

No View State

Invoked through JS API

Invokes JS Callback

@remoteAction

global static String myMethod(String

inputParam){

...

}

Page 14: S1 and Visualforce Publisher Actions

Calling Apex Remote Action

Visualforce.remoting.Manager.invokeAction(’

{!

$RemoteAction.RemoteClass.methodName}',

param,

function(result, event) {

//...callback to handle result

});

Page 15: S1 and Visualforce Publisher Actions

Event Object: Success Example

{

"statusCode":200,

"type":"rpc",

"ref":false,

"action":"IncidentReport",

"method":"createIncidentReport",

"result":"a072000000pt1ZLAAY",

"status":true

}

Page 16: S1 and Visualforce Publisher Actions

Event Object: Failure Example{

"statusCode":400,

"type":"exception",

"action":"IncidentReport",

"method":"createIncidentReport",

"message":"List has more than 1 row for assignment to SObject",

"data": {"0":

{"Merchandise__c":"a052000000GUgYgAAL","Type__c":"Accident","Desc

ription__c":"This is an accident report"}},

"result":null,

"status":false

}

Page 17: S1 and Visualforce Publisher Actions

Interacting with the Publisher: Allow Submit

Make Submit Active

Payload true/false

Sfdc.canvas.publisher.publish(

{

name: "publisher.setValidForSubmit",

payload:true

});

Page 18: S1 and Visualforce Publisher Actions

Interacting with the Publisher: Subscribe to Submit

Attach to Submit Event Sfdc.canvas.publisher.subscribe({

name: "publisher.post",

onData:function(e) {

// This subscribe fires when the user hits 'Submit'

in the publisher

postToFeed();

}});

Page 19: S1 and Visualforce Publisher Actions

Interacting with the Publisher: Close Publisher

Make the Submit Happen

Sfdc.canvas.publisher.publish({name:

"publisher.close", payload:

{ refresh:"true"}});

Page 20: S1 and Visualforce Publisher Actions

REST API

For large data transactions

Use forcetk library for easy access.

github.com/developerforce/Force.com-JavaScript-REST-Toolkit

Page 21: S1 and Visualforce Publisher Actions

forcetk: Init and Bind To Session

<apex:includeScript value="{!$Resource.forcetk}"/>

...

var restClient = new forcetk.Client();

var contentId;

var merchId;

restClient.setSessionToken('{!$Api.Session_ID}');

//turn off proxy now that we have session

restClient.proxyUrl = null;

restClient.instanceUrl = '';

Page 22: S1 and Visualforce Publisher Actions

forcetk: Init and Bind To Session

restClient.create('ContentVersion', {

"Origin": "H",

"PathOnClient": file.name,

"VersionData": imageData

}, function(data) {

...

$('#test-display').text('File Create Complete:' + data.id);

...

}, onErrorSfdc);

Page 23: S1 and Visualforce Publisher Actions

Spring ’14(Developer Preview)

Page 24: S1 and Visualforce Publisher Actions

Remote Objects Standard CRUD/Q functionality without Apex

Similar to remoteTK or SObjectData

Visualforce components define data models

<apex:jsSObjectBase shortcut="tickets"> <apex:jsSObjectModel name="Ticket__c" /> <apex:jsSObjectModel name="Contact" fields="Email" /> <script> var contact = new tickets.Contact();

contact.retrieve({ where: { Email: { like: query + '%' } } }, function(err, data) {