Salesforce1 Platform for programmers

  • View

  • Download

Embed Size (px)

Text of Salesforce1 Platform for programmers

1. Salesforce1 Platform for Programmers 2. Herv Maleville Solution Engineer - Platform @hmaleville 3. 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 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 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-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., inc. assumes no obligation and does not intend to update these forward-looking statements. 4. Be interactive 5. Free Developer Environment 6. Online Workbook 7. Salesforce is a Platform Company. Period. -Alex Williams, TechCrunch 1B+ API Calls Per Day6B Lines of Apex 4M+ Apps Built on the Platform 72B Records Stored Salesforce1 Platform 8. 1.4 millionand growing 9. Core Services Chatter Multi- language Translation Workbench Email ServicesAnalytics Cloud Database Schema 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 10. 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 11. Your App Every Object, Every Field: API Enabled GET POST PATCH DELETE OAuth 2.0 HTTPS 12. Every Object, Every Field: Apex and Visualforce Enabled Visualforce Pages Visualforce Components Apex Controllers Apex Triggers Custom UICustom UI Custom LogicCustom Logic 13. 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 14. 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? 15. Apex Cloud-based programming language on Salesforce1 16. Introduction to Apex Object-Oriented Language Dot Notation Syntax Cloud based compiling, debugging and unit testing 17. 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 18. Developer Console Browser Based IDE Create and Edit Classes Create and Edit Triggers Run Unit Tests Review Debug Logs 19. Unit Testing Code which asserts that existing logic is operating correctly 20. Code to test code Tests can mirror user expectations System Asserts increase predictability Line Coverage increase predictability Unit Testing 21. 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? 22. Basic Unit Test Structure @isTest public class TestClase{ @isTest static void testCase(){ //setup test data List contacts = ContactFactory.createTestContacts(); //process / perform logic EvaluateContacts.process(contacts); //assert outcome System.assertEquals(EvaluateContacts.processed.size(),contacts.size()); } } 23. 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 } 24. ProTip: Load Static Resource Data from CSV List invoices = Test.loadData(Invoice__c.sObjectType, 'InvoiceData'); update invoices; 25. 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 Test.StopTest(); System.assertEquals(a,b); //now begin assertions 26. Apex Triggers Event Based Logic Associated with Object Types Before or After: Insert Update Delete Undelete 27. 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(; 28. Scheduled Apex Interface for scheduling Apex jobs 29. 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(); } } 30. System.schedule('testSchedule','0 0 13 * * ?', new WarehouseUtil());Via Apex Via Web UI Schedulable Interface 31. Batch Apex Apex interface for processing large datasets asynchronously 32. 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 33. Batchable Interface global with sharing class WHUtil implements Database.Batchable { global Database.QueryLocator start(Database.BatchableContext BC) { //Start on next context } global void execute(Database.BatchableContext BC, Listscope) { //Execute on current scope } global void finish(Database.BatchableContext BC) { //Finish and clean up context } } 34. ProTip: 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 35. Apex Integration Using Apex with third party systems 36. Apex HTTP public FlickrList getFlickrData(string tag) { HttpRequest req = new HttpRequest(); req.setMethod('GET'); req.setEndpoint(' nojsoncallback=1&format=json&tags='+tag); HTTP http = new HTTP(); HTTPResponse res = http.send(req); return (FlickrList)JSON.deserialize(res.getBody().replace(''',''),FlickrList.class ); } 37. 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/ 38. ProTip: Unit Tests: Mock HTTP Endpoints @isTest global class MyMockHttp 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; } } 39. Unit Tests: Mock HTTP Endpoints @isTest private class CalloutClassTest { static void testCallout() { Test.setMock(HttpCalloutMock.class, new MyMockHttp()); HttpResponse res = CalloutClass.getInfoFromExternalServ