Elevate workshop programmatic_2014
Upcoming SlideShare
Loading in...5
×
 

Elevate workshop programmatic_2014

on

  • 316 views

 

Statistics

Views

Total Views
316
Views on SlideShare
316
Embed Views
0

Actions

Likes
1
Downloads
3
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • The recommended agenda can be found here: <br /> https://docs.google.com/a/salesforce.com/spreadsheet/ccc?key=0Akr6pvkAv8X5dGFEN2ZWNUxWbS1SVFBoRS1oZU5kQWc&usp=drive_web#gid=22 <br /> Under the “Workshop: S1 Programmer” tab <br /> Errors, comments, suggestions in either the deck or the workbook can be mentioned on Josh Birk’s Chatter feed, or written up in Google Docs and shared with Josh Birk and Mario Korf. <br /> There is a demo org for the Warehouse ELEVATE here: <br /> https://login.salesforce.com/?un=elevate@demo.com&pw=demo1234 <br /> It has: <br /> Enhanced Data Model <br /> The workflows, etc from the Basic class <br /> The Apex and VF from the Programmers class <br /> Canvas definitions from the Programmers class <br /> - including the Create_Delivery Invoice action <br /> FlickrView (also known as PuppyForce) <br /> Chatter Blacklist <br /> BEFORE YOU PRESENT – go through the slides and update: <br /> YOUR NAME(S) <br /> TWITTER/EMAIL <br /> LUNCH INFO <br /> BITLY SURVEY LINK <br /> DUG INFORMATION <br /> As these are just placeholders in the slides right now. <br /> THESE SPEAKER NOTES ARE NOT VERBATIM. They are there just as hints as to what to cover. <br />
  • Introduce the day. Poll the audience for level of experience. You’ll want to know who is a Java dev and who is a new or experienced to our platform. <br />
  • Introduce Yourselves <br /> Note: this is a slide if there is more than one presenter <br />
  • Introduce Yourselves <br /> Note: this is a slide if there is only one presenter <br />
  • Introduce Yourselves <br /> Note: this is a slide if there is more than one presenter <br />
  • Safe Harbor <br />
  • Change this slide to match the local internet requirements. <br />
  • Highlight that this is not just a day of talking to them, this is a dialogue and they should ask questions as they like – even ones that don’t pertain to the current “section”. Projects they’re working on, features they have heard about, etc. <br />
  • Since there may be experienced devs, invite the to use the IDE of their choice (Sublime, Eclipse) even if the tutorials point to Dev Console <br />
  • They should create a brand new DE org if they have not done so recently. They should not use a Trial, Sandbox or Production org. <br /> Emphasize our DE orgs are free and do not expire (they are not product trials) <br />
  • THIS IS THE ONLINE VERSION OF THE NEW WORKBOOK DRAFT <br />
  • Salesforce is often thought of as a CRM company, but these stats show we have platform services in use as well <br />
  • 1.4 million includes Force.com, Heroku and ExactTarget <br />
  • Our platform is not merely a cloud hosting service, it is a series of tools and features that enable developers to be successful. <br />
  • On our platform, as you building your data model – you are getting a lot more than just a relational database. You get a mobile app, right out of the gate. <br />
  • You get our API’s, automatically extended: REST, SOAP, Bulk, Streaming <br />
  • And our programmatic features are automatically aware of the data model as well. <br />
  • Now some of you might have worked with out Warehouse demo application before. If you haven’t here’s a quick recap. <br />
  • These are the core business requirements of the Warehouse application <br />
  • Here is an overview of what our data model will look like. <br /> POTENTIAL DEMO: View this in Schema Builder <br />
  • This is our first “pro tip” slide. Using these kinds of fields can increase SOQL searches. <br />
  • Our Basics workshop covers the declarative side of our platform, but let’s do a quick review. <br />
  • Here is an overview of what our data model will look like. <br /> POTENTIAL DEMO: View this in Schema Builder <br />
  • OK, this is a quick break to make sure everyone is up and running. The workbook walks through installing the warehouse model, creating some test data and basically making sure your DE org is setup correctly. Let’s take a chance to do that. <br />
  • For when declarative logic is not enough, we provide Apex. Apex is a cloud-based programming language, very similar to Java – except that you can code, compile and deploy all right from your Salesforce instance. You’ll see how we can create robust programmatic functions right from your browser. <br />
  • If you are familiar with Java or C#, you are going to be familiar with Apex. It is OO and uses dot notation. However, Apex is completely cloud based – you can compile and debug right in your browser. Because it runs right in your instance it is also a “first class” citizen – meaning we can do actions right within Apex without any additional configuration or libraries. <br />
  • Let’s take a look at an example Apex class <br />
  • That’s what Apex is – how do we code it? It is possible to use a third party IDE like Sublime or Eclipse – but you can also code right in your browser. Our Developer Console allows you to create and edit code, debug your applications and run unit tests. <br /> POTENTIAL DEMO: Show Anonymous Apex in the Dev Console <br />
  • This will be a quick review for the Force.com devs in the room. <br />
  • That is a picture of the first ever bug. Yes, it was a real bug. To keep bugs from happening, we use unit testing. <br />
  • Basic overview of how Unit Testing works <br /> POTENTIAL DEMO: Walk through TestInvoiceStatementDeletion on the demo org and run the test <br />
  • Basic overview of how Unit Testing works <br /> POTENTIAL DEMO: Walk through TestInvoiceStatementDeletion on the demo org and run the test <br />
  • Pro tip: You may want to have a unit test follow a scenario based on a specific profile. It’s pretty easy to do. <br />
  • Pro tip: You may want to have a unit test follow a scenario based on a specific profile. It’s pretty easy to do. <br />
  • Pro tip: You can also load your test data off a static resource, it is easier to handle large data sets and and test data can be swapped out easily. <br />
  • Pro tip: You can also load your test data off a static resource, it is easier to handle large data sets and and test data can be swapped out easily. <br />
  • Overview of Apex Triggers <br />
  • Pro tip: Best to use on trigger per logic, and then you can control the flow of the logic with the system levelTrigger variable <br />
  • Pro tip: Triggers retain scope during an execution, so if want to keep them from being hit again and again (based on other updates/workflows) you can use a static flag on the trigger to turn it “off” <br />
  • Pro tip: We can use Triggers on Chatter. In fact: <br /> Potential Demo: Chatter Blacklist <br />
  • OK, now we have two tutorials. The first is building a simple trigger on the plaform and then there is a walkthrough of a unit test. <br /> For the vets in the room, we’ve got a little extra credit challenge. This is in the form of a gist online, but it walks you through a more advanced version of a trigger. <br />
  • Update this slide with specifics about lunch <br />
  • Scheduled Apex allows us to run business logic in the background at specific intervals <br />
  • It uses the Schedulable interface, which allows us define the execute method to control what logic will be run on the schedule <br />
  • You can define the schedule in two ways <br />
  • We also have Batch Apex, which is a close cousin to Scheduled Apex <br />
  • Batch apex allows us to queue up data and have logic run against it asynchronously. <br />
  • The interface itself allows us to introduce logic when a queue of objects is being run. <br /> POTENTIAL DEMO: CleanUpRecords <br />
  • PRO Tip: Remember when we talked about controlling context with Start and Stop test? This is also works for batch processing. <br />
  • At the beginning we talked about how your data model is automatically extended with our API’s. So out of the box, no programming, you get REST and SOAP endpoints to query and manipulate data. Basic CRUD stuff. You also get our Bulk and Streaming API for free – but we don’t have time to cover those here. <br /> You can also expose custom logic via endpoints using Apex. <br />
  • We are going to focus on Apex REST today. This is how you setup an Apex REST class. The RestResource annotation defines the actual endpoint. Methods are then assigned an HTTP method. So when we hit the CaseManagement endpoint here, and we send it an HTTP Post request … it will hit the attachPic method. <br /> Potential DEMO: Workbench operating against MerchandiseManager class <br />
  • Pro Tip: In your unit test, you can fake a third party endpoint. You generate a class that will a mock a return. <br />
  • Then you sub that endpoint for what the real code will hit when it attempts to call out. <br />
  • OK, two more tutorials – the first on Batch processing and then another on Apex REST. <br />
  • Visualforce is the user interface sibling to Apex. It also runs in the cloud, in your instance – and it allows you to create brand new experiences for your customers and users. <br />
  • What do we mean by components? Well you’d start with a page component, and that will define how the whole page is going to be rendered. And then you can add things like a form and fields for the form. Now everything you see here will be HTML when it gets outputted. So you’d have and HTML form, HTML input tags, etc. To the browser, it is just standard HTML. <br /> But how are we binding data here? We define a controller, which gets access to server-side logic. Whenever you see these brackets and that exclamation point, you’re looking at dynamically bound data which will effect how the component is rendered. <br /> However, the server-side logic here is a little interesting. <br /> POTENTIAL DEMO: Do Standard Controller demo, then go back to describe custom controllers and extensions. <br />
  • However what we just saw there is using a viewstate. If you aren’t familiar with a viewstate, it’s a block of hashed information on the client which tracks changes – allowing us to get around the fact that HTTP is stateless. <br />
  • We have options, though. While a lot of Visualforce relies on bound forms to transmit data (and a viewstate), we can also talk directly to Apex via JavaScript and avoid the viewstate. This is more JavaScript friendly and also has a small footprint. <br />
  • We have options, though. While a lot of Visualforce relies on bound forms to transmit data (and a viewstate), we can also talk directly to Apex via JavaScript and avoid the viewstate. This is more JavaScript friendly and also has a small footprint. <br /> DEMO: JS Remoting. You could preview FindNearby, or you could do a quick example on the fly. <br />
  • The data is going to come back to us in JSON. Note that result here might be a string, or JSON representation of an array or object. <br />
  • Or we’ll see an error <br /> DEMO: JS Remoting <br />
  • In Spring ’14 we are rolling out a preview of a new feature called Remote Objects. It lets us perform CRUD functionality without having to write an Apex class, kind of like a Standard Controller. <br />
  • So a quick overview. <br />
  • Now we have a tutorial on writing a Visualforce page. This page is designed to run in Salesforce1, and uses JavaScript Remoting to locate nearby warehouses. <br />
  • Let’s talk about another kind of user interface. This is one you might already have built out, running on your own network. How can we best integrate that back into Salesforce? <br />
  • Canvas makes that easy. With a connected app defined, Canvas handles the authentication of the current user against the third party UI. The external application can be anything the user would normally be able to see in their browser. It can then make API calls on the user’s behalf. <br />
  • We have API’s to fit a wide range of use cases. Our REST API is very versatile, and one of the main use cases is mobile applications – and Canvas relies on the REST API to make calls back into Salesforce. <br />
  • Before we can make a callout though, we need to authenticate right? Canvas makes this easy, and it uses two methods – but both are similar and based on the flow of OAuth. OAuth is used by Google, Facebook, Twitter, pretty much everyone on the planet to securely authenticate first party credentials with third party apps. <br />
  • Let’s walk through the flow of OAuth. <br /> Demo: A great one here could be Forcecraft <br />
  • OK, this tutorial walks us through two different applications using Canvas. <br />
  • Update this slide with local DUG information <br />
  • THESE SLIDES ARE OPTIONAL DEPENDING ON TIME <br /> For instance, we talked about how your data model automatically extends what VF and Apex can do – but what about our API’s? We have several. <br />
  • THESE SLIDES ARE OPTIONAL DEPENDING ON TIME <br /> Salesforce1 Mobile is one of our offerings, but you can also create your own custom applications. <br /> POTENTIAL DEMO: Quick Start on forceios / forcedroid <br />
  • THIS SLIDE MAY ALSO HAVE BEEN COVERED BY AN ISV SPEAKER <br /> THESE SLIDES ARE OPTIONAL DEPENDING ON TIME <br /> We also have an entire marketplace for finding, buying and selling apps. <br /> NOTE: Chatter Blacklist as a Labs App (Free and Unmanaged) <br />
  • THESE SLIDES ARE OPTIONAL DEPENDING ON TIME <br /> Heroku provides a framework for easily deploying the applications in the language of your choice. <br /> POTENTIAL DEMO: Quick PHP deployment. <br />
  • Introduce Yourselves <br /> Note: this is a slide if there is more than one presenter <br />
  • Introduce Yourselves <br /> Note: this is a slide if there is more than one presenter <br />
  • statue <br />

Elevate workshop programmatic_2014 Elevate workshop programmatic_2014 Presentation Transcript

  • Salesforce1 Platform for Programmers
  • @forcedotcom @joshbirk @metadaddy #forcedotcom #askforce David Scruggs Principal Platform Engineer @davescruggs In/dscruggs dscruggs@salesforce.com Stewart Loewen Solution Strategist /in/stewartloewen sloewen@salesforce.com
  • 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 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.
  • Login and get ready UofM Wireless Internet Instructions On Each Table
  • Be interactive
  • For the Eclipse fans in the room Use the Editor of Your Choice
  • http://developer.force.com/join Free Developer Environment
  • Online Workbook http://bit.ly/force_apex_book
  • Salesforce is a Platform Company. Period. -Alex Williams, TechCrunch 500M API Calls Per Day6B Lines of Apex 4M+ Apps Built on the Platform 72B Records Stored Salesforce1 Platform
  • 1.4 million…and growing
  • Core Services Chatter Multi- language Translation Workbench Email ServicesAnalytics Cloud Database Scheema Builder Search Visualforce MonitoringMulti-tenant Apex Data-level Security Workflows APIs Mobile Services Social APIs Analytics APIs Bulk APIsRest APIs Metadata APIs Soap APIs Private App Exchange Custom Actions Identity Mobile Notifications Tooling APIs Mobile Packs Mobile SDK Offline Support Streaming APIs Geolocation ET 1:1 ET Fuel Heroku1 Heroku Add-Ons Sharing Model ET API Salesforce1 Platform
  • Every Object, Every Field: Salesforce1 Mobile Accessible AppExchange Apps: Dropbox Concur Evernote ServiceMax More Custom Apps and Integrations: SAP Oracle Everything Custom More Sales, Service and Marketing Accounts Cases Campaigns Dashboards More
  • Your App Every Object, Every Field: API Enabled GET POST PATCH DELETE OAuth 2.0 HTTPS
  • Every Object, Every Field: Apex and Visualforce Enabled Visualforce Pages Visualforce Components Apex Controllers Apex Triggers Custom UICustom UI Custom LogicCustom Logic
  • Warehouse Application Requirements • Track price and inventory on hand for all merchandise • Create invoices containing one or more merchandise items as a line items • Present total invoice amount and current shipping status
  • Warehouse Data Model Merchandise Name Price Inventory Pinot $20 15 Cabernet $30 10 Malbec $20 20 Zinfandel $10 50 Invoice Number Status Count Total INV-01 Shipped 16 $370 INV-02 New 20 $200 Invoice Line Items Invoice Line Merchandise Units Sold Unit Price Value INV-01 1 Pinot 1 15 $20 INV-01 2 Cabernet 5 10 $150 INV-01 3 Malbec 10 20 $200 INV-02 1 Pinot 20 50 $200
  • Indexed Field • Primary Keys • Id • Name • OwnerId • Audit Dates • Created Date • Last Modified Date • Foreign Keys • Lookups • Master-Detail • CreatedBy • External ID Fields • External ID Fields • Unique Fields • Fields indexed by Salesforce Using a query with two or more indexed filters greatly increases performance
  • Two Approaches to Development Visualforce Pages Visualforce Components Apex Controllers Apex Triggers Metadata API REST API Bulk API Formula Fields Validation Rules Workflows and Approvals Custom Objects Custom Fields Relationships Page Layouts Record Types User Interface Business Logic Data Model Declarative Approach Programmatic Approach
  • Declarative before Programmatic Use declarative features when possible: • Quicker to build • Easier to maintain and debug • Possible addition of new features • Do not count against governor limits For example: • Will a workflow suffice instead of a trigger? • Will a custom layout work instead of Visualforce?
  • Warehouse Data Model Merchandise Name Price Inventory Pinot $20 15 Cabernet $30 10 Malbec $20 20 Zinfandel $10 50 Invoice Number Status Count Total INV-01 Shipped 16 $370 INV-02 New 20 $200 Invoice Line Items Invoice Line Merchandise Units Sold Unit Price Value INV-01 1 Pinot 1 20 $20 INV-01 2 Cabernet 5 10 $150 INV-01 3 Malbec 10 20 $200 INV-02 1 Pinot 20 50 $200 Workflow Rule When inserted, if unit price is blank then fill it with the Merchandise price value
  • Hands On Tutorials #1: Setup your Environment
  • Apex Cloud-based programming language on Salesforce1
  • Introduction to Apex • Object-Oriented Language • Dot Notation Syntax • Cloud based compiling, debugging and unit testing • “First Class” Citizen on the Platform
  • public with sharing class myControllerExtension implements Util { private final Account acct; public Contact newContact {get; set;} public myControllerExtension(ApexPages.StandardController stdController) { this.acct = (Account)stdController.getRecord(); } public PageReference associateNewContact(Id cid) { newContact = [SELECT Id, Account from Contact WHERE Id =: cid LIMIT 1]; newContact.Account = acct; update newContact; } } Apex Anatomy Class and Interface based Scoped Variables Inline SOQL Inline DML
  • Developer Console • Browser Based IDE • Create and Edit Classes • Create and Edit Triggers • Run Unit Tests • Review Debug Logs
  • Hands On Tutorials #2: Using the Dev Console #3: Creating Apex Classes Extra Credit: http://bit.ly/ELEVATE-Apex-Email-EC
  • Unit Testing Code which asserts that existing logic is operating correctly
  • • Code to test code • Tests can mirror user expecations • System Asserts increase predictability • Line Coverage increase predictability Unit Testing
  • Unit Testing in Apex  Built in support for testing – Test Utility Class Annotation – Test Method Annotation – Test Data build up and tear down  Unit test coverage is required – Must have at least 75% of code covered  Why is it required?
  • Basic Unit Test Structure @isTest public class TestClase{ @isTest static void testCase(){ //setup test data List<Contact> contacts = ContactFactory.createTestContacts(); //process / perform logic EvaluateContacts.process(contacts); //assert outcome System.assertEquals(EvaluateContacts.processed.size(),contacts.size()); } }
  • Testing Permissions //Set up user User u1 = [SELECT Id FROM User WHERE Alias='auser']; //Run As U1 System.RunAs(u1){ //do stuff only u1 can do }
  • Static Resource Data List<Invoice__c> invoices = Test.loadData(Invoice__c.sObjectType, 'InvoiceData'); update invoices;
  • Testing Context and Asynchronous Behavior // this is where the context of your test begins Test.StartTest(); //execute future calls, batch apex, scheduled apex UtilityRESTClass.performCallout(); // this is where the context ends Text.StopTest(); System.assertEquals(a,b); //now begin assertions
  • Apex Triggers • Event Based Logic • Associated with Object Types • Before or After: • Insert • Update • Delete • Undelete
  • Controlling Flow trigger LineItemTrigger on Line_Item__c (before insert, before update) { //separate before and after if(Trigger.isBefore) { //separate events if(Trigger.isInsert) { System.debug(‘BEFORE INSERT’); DelegateClass.performLogic(Trigger.new);
  • Static Flags public with sharing class AccUpdatesControl { // This class is used to set flag to prevent multiple calls public static boolean calledOnce = false; public static boolean ProdUpdateTrigger = false; }
  • Chatter Triggers trigger AddRegexTrigger on Blacklisted_Word__c (before insert, before update) { for (Blacklisted_Word__c f : trigger.new) { if(f.Custom_Expression__c != NULL) { f.Word__c = ''; f.Match_Whole_Words_Only__c = false; f.RegexValue__c = f.Custom_Expression__c; } } }
  • Hands On Tutorials #4: Apex Triggers #5: Apex Unit Tests Extra Credit: http://bit.ly/ELEV-triggers http://bit.ly/ELEVATE-Mock-Endpoint-EC
  • LUNCHLunch Down the hall
  • Scheduled Apex Interface for scheduling Apex jobs
  • Schedulable Interface global with sharing class WarehouseUtil implements Schedulable { //General constructor global WarehouseUtil() {} //Scheduled execute global void execute(SchedulableContext ctx) { //Use static method for checking dated invoices WarehouseUtil.checkForDatedInvoices(); }
  • System.schedule('testSchedule','0 0 13 * * ?', new WarehouseUtil());Via Apex Via Web UI Schedulable Interface
  • Batch Apex Apex interface for processing large datasets asynchronously
  • Apex Batch Processing  Governor Limits – Various limitations around resource usage  Asynchronous processing – Send your job to a queue and we promise to run it  Can be scheduled to run later – Kind of like a cron job
  • Batchable Interface global with sharing class WHUtil implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext BC) { //Start on next context } global void execute(Database.BatchableContext BC, List<sObject>scope) { //Execute on current scope } global void finish(Database.BatchableContext BC) { //Finish and clean up context } }
  • Unit Testing Asynchronous Apex //setup test data Test.StartTest(); System.schedule('testSchedule','0 0 13 * * ?',new,WarehouseUtil()); ID batchprocessid = Database.executeBatch(new WarehouseUtil()); Test.StopTest(); //assert outcomes
  • Apex Integration Using Apex with third party systems
  • Apex HTTP public FlickrList getFlickrData(string tag) { HttpRequest req = new HttpRequest(); req.setMethod('GET'); req.setEndpoint('http://api.flickr.com/services/feeds/photos_public.gne? nojsoncallback=1&format=json&tags='+tag); HTTP http = new HTTP(); HTTPResponse res = http.send(req); return (FlickrList)JSON.deserialize(res.getBody().replace(''',''),FlickrList.class ); }
  • Apex REST @RestResource(urlMapping='/CaseManagement/v1/*') global with sharing class CaseMgmtService { @HttpPost global static String attachPic(){ RestRequest req = RestContext.request; RestResponse res = Restcontext.response; Id caseId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); Blob picture = req.requestBody; Attachment a = new Attachment (ParentId = caseId, Body = picture, ContentType = 'image/
  • Unit Tests: Mock HTTP Endpoints @isTest global class MockHttp implements HttpCalloutMock { global HTTPResponse respond(HTTPRequest req) { // Create a fake response HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); res.setBody('{"foo":"bar"}'); res.setStatusCode(200); return res; } }
  • Unit Tests: Mock HTTP Endpoints @isTest private class CalloutClassTest { static void testCallout() { Test.setMock(HttpCalloutMock.class, new MockHttp()); HttpResponse res = CalloutClass.getInfoFromExternalService(); // Verify response received contains fake values String actualValue = res.getBody(); String expectedValue = '{"foo":"bar"}'; System.assertEquals(actualValue, expectedValue); } }
  • Hands On Tutorials #6: Apex Batch Processing #7: Apex REST Extra Credit: http://bit.ly/ELEVATE-REST-Response-EC
  • Visualforce Component-based user interface framework on Salesforce1
  • Visualforce Components <apex:page StandardController="Contact” extensions="duplicateUtility” action="{!checkPhone}”> <apex:form> <apex:outputField var="{!Contact.FirstName}” /> <apex:outputField var="{!Contact.LastName}" /> <apex:inputField var="{!Contact.Phone}" /> <apex:commandButton value="Update" action="{!quicksave}" /> </apex:form> </apex:page> Standard & Custom Controllers Custom Extensions Data bound components Controller Callbacks
  • Hashed information block to track server side transports Viewstate
  •  Apex Forms – Visualforce component bound to an Apex Method  Javascript Remoting – Annotated Apex methods exposed to JavaScript Interacting with Apex
  • Using JavaScript Remoting Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.ContactExtension.makeContact}', “003i000000cxdHP”, “Barr” function(result, event) { //...callback to handle result alert(result.LastName); }); @RemoteAction global static Contact makeContact (String cid, String lname) { return new Contact(id=cid,Last_Name=lname); } ApexVisualforce
  • Sample Success Message { "statusCode":200, "type":"rpc", "ref":false, "action":"IncidentReport", "method":"createIncidentReport", "result":"a072000000pt1ZLAAY", "status":true }
  • Sample Error Message { "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", "Description__c":"This is an accident report"}}, "result":null, "status":false }
  • Remote Objects (Preview in Spring ’14) <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) { //handle query results here CRUD/Q Functionality Data Model Components JavaScript Framework Friendly
  • Interacting with Apex • ActionFunction allows direct binding of variables • ActionFunction requires ViewState • JavaScript Remoting binds to static methods • JavaScript Remoting uses no ViewState • Transient, Private and Static reduce Viewstate
  • Hands On Tutorials #8: Salesforce1 Visualforce Extra Credit: http://bit.ly/ELEVATE-Streaming-EC
  • Canvas Framework for embedding third party apps into Salesforce
  • How Canvas Works • Only has to be accessible from the user’s browser • Authentication via OAuth or Signed Response • JavaScript based SDK can be associated with any language • Within Canvas, the App can make API calls as the current user • apex:CanvasApp allows embedding via Visualforce Any Language, Any Platform
  • Using publisher.js Sfdc.canvas.publisher.subscribe({ name: "publisher.post", onData: function(e) { // fires when the user hits 'Submit' postToFeed(); } }); Sfdc.canvas.publisher.publish({ name: "publisher.close", payload: { refresh:"true"} });
  • API Leveraging industry standard HTTP REST API
  • OAuth Industry standard for authenticating users for third party apps
  • Remote Application Salesforce1 Platform Sends App Credentials User logs in, Token sent to callback Confirms token Send access token Maintain session with refresh token OAuth2 Authentication Flow
  • Hands On Tutorials #9: Salesforce1 Canvas Recess: bit.ly/Forcecraft
  • Double-click to enter title Double-click to enter text The Wrap Up
  • Survey: http://bit.ly/MSP_Survey Slides: http://bit.ly/apex_workshop_slides
  • Double-click to enter title Double-click to enter text http://developer.force.com
  • Developer Groups Join a Salesforce Developer Group http://bit.ly/fdc-dugs Twin Cities Developer Group http://www.meetup.com/SFTCDUG/ Become a User Group Leader Email: April Nassi <anassi@salesforce.com>
  • LUNCHSalesforce1 APIs Family of APIs on the Salesforce1 Platform
  • LUNCHMobile SDK Development Kit for building hybrid and native iOS and Android apps
  • LUNCHAppExchange Enterprise marketplace for Salesforce1 Apps
  • LUNCHHeroku Polyglot framework for hosting applications
  • @forcedotcom @joshbirk @metadaddy #forcedotcom #askforce
  • Joshua Birk Developer Evangelist @joshbirk joshua.birk@salesforce.com Matthew Reiser Solution Architect @Matthew_Reiser mreiser@salesforce.com
  • simplicity is the ultimate form of sophistication - Da Vinci
  • Thank You