elevate paris

73
Advanced Developer Workshop Peter Chittum Developer Evangelist @pchittum [email protected] Hervé Maleville Platform Architect @hmaleville [email protected]

Upload: peter-chittum

Post on 11-May-2015

354 views

Category:

Technology


0 download

DESCRIPTION

Slides for ELEVATE Workshop à Paris 3 avril, 2014.

TRANSCRIPT

Page 1: ELEVATE Paris

Advanced Developer Workshop

Peter ChittumDeveloper Evangelist@[email protected]

Hervé MalevillePlatform [email protected]@salesforce.com

Page 2: ELEVATE Paris

Wifi AccessSSID: GuestPassword: fBSuBLqe

http://bit.ly/elevate_adv_workbook

Login and Get Ready

Page 3: ELEVATE Paris

Be Interactive

Page 4: ELEVATE Paris

Free Developer

Environment

http://developer.force.com/join

Page 5: ELEVATE Paris

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.

Page 6: ELEVATE Paris

Nos prochains évènements à Paris!

Salesforce1 Tour à Paris

Webinar en Français: Data Model & Relationships

Prenez le lead sur notre communauté de Développeurs en France !

Plus d’information sur www.developer.salesforce.com

June 26th

April 29th

A vous de jouer

Page 7: ELEVATE Paris

Core Services

Chatter

Multi-langua

ge

Translation

Workbench

Email Services

Analytics

CloudDatabase

Scheema

Builder

Search

Visualforce

Monitoring

Multi-tenant

Apex

Data-level

Security

Workflows

APIs

Mobile Services

Social

APIs

Analytics

APIs

Bulk APIs

Rest APIs

Metadata

APIs

Soap APIs

Private App

Exchange

Custom

Actions

Identity

Mobile Notificat

ions

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

Page 8: ELEVATE Paris

Salesforce is a Platform Company. Period.-Alex Williams, TechCrunch

600MAPI Calls Per Day6BLines of

Apex4M+Apps Built on the Platform

72BRecords Stored

Salesforce1 Platform

Page 9: ELEVATE Paris

1.5 Million

Page 10: ELEVATE Paris

Editor Of ChoiceFor the Eclipse fans in the room

Page 11: ELEVATE Paris
Page 12: ELEVATE Paris

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

Page 13: ELEVATE Paris

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

Page 14: ELEVATE Paris

Apex

Page 15: ELEVATE Paris

Introduction to Apex

Object-Oriented Language

Dot Notation Syntax

Case Insenstive

“First Class” Citizen on the Platform

Page 16: ELEVATE Paris

Apex Anatomy

Chapter 1:

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; }}

Class and Interface based

Scoped Variables

Inline SOQL

Inline DML

Page 17: ELEVATE Paris

Developer Console

Browser Based IDE

Create and Edit Classes

Create and Edit Triggers

Run Unit Tests

Review Debug Logs

Page 18: ELEVATE Paris

Apex Triggers

Event Based Logic

Associated with Object

Types

Before or After:

Insert

Update

Delete

Undelete

Page 19: ELEVATE Paris

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);

Page 20: ELEVATE Paris

Static Flags

public with sharing class AccUpdatesControl { // This class is used to prevent multiple calls public static boolean calledOnce = false; public static boolean ProdUpdateTrigger = false;}

Page 21: ELEVATE Paris

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; } }}

Page 22: ELEVATE Paris

Trigger Tutorial

Basic: Tutorial 2

Intermediate: Tutorial 4

Beyond Intermediate: http://bit.ly/ELEV-triggers

http://bit.ly/elevate_adv_workbook

Page 23: ELEVATE Paris

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?

Page 24: ELEVATE Paris

Unit Testing

• Declare Classes/Code as Test

• isTest Annotation

• testmethod keyword

• Default data scope is test only

Page 25: ELEVATE Paris

Testing Context

// this is where the context of your test beginsTest.StartTest();

//execute future calls, batch apex, scheduled apex

// this is where the context endsText.StopTest(); System.assertEquals(a,b); //now begin assertions

Page 26: ELEVATE Paris

Testing Permissions

//Set up userUser u1 = [SELECT Id FROM User WHERE Alias='auser']; //Run As U1System.RunAs(u1){ //do stuff only u1 can do}

Page 27: ELEVATE Paris

Static Resource Data

List<Invoice__c> invoices = Test.loadData(Invoice__c.sObjectType, 'InvoiceData');update invoices;

Page 28: ELEVATE Paris

Mock HTTP Endpoints

@isTestglobal 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; }}

Page 29: ELEVATE Paris

Mock HTTP Endpoints

@isTestprivate 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); }}

Page 30: ELEVATE Paris

Unit Testing Tutorial

Page 31: ELEVATE Paris

Batch Apex

Page 32: ELEVATE Paris

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 chron job

Page 33: ELEVATE Paris

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 } }

Page 34: ELEVATE Paris

Implementing Apex Batch Processing

Apex Batch Processing Tutorial

Page 35: ELEVATE Paris

Scheduled Apex

Page 36: ELEVATE Paris

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(); }}

Page 37: ELEVATE Paris

Schedulable Interface

System.schedule('testSchedule','0 0 13 * * ?',new WarehouseUtil());Via Apex

Via Web UI

Page 38: ELEVATE Paris

Unit Testing Batch Apex

Test.StartTest();

System.schedule(‘once','0 0 13 * * ?',new,WarehouseUtil());

ID batchprocessid = Database.executeBatch(new WarehouseUtil());

Test.StopTest();

Page 39: ELEVATE Paris

Scheduling Apex

Apex Scheduling Tutorial

Page 40: ELEVATE Paris

Apex REST Services

Page 41: ELEVATE Paris

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/

Page 42: ELEVATE Paris

Apex REST Services

REST Services with Apex Tutorial

Page 43: ELEVATE Paris

Visualforce

Page 44: ELEVATE Paris

Framework

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

Easily create salesforce UI

Standard-compliant

Can Interact With Apex for Custom Logic

Page 45: ELEVATE Paris

Visualforce Tags

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

<apex:input type=“email”/>

<apex:pageBlockSection collapsible=“false” />

Page 46: ELEVATE Paris

Hashed information block to track server side transports

Viewstate

Page 47: ELEVATE Paris

Apex Form

Required for standard salesforce post

Incurs Viewstate Overhead

<apex:form> …</apex:form

aspdoifuapknva894372h4ofincao98vh0q938hfoqiwnbdco8q73h0o9fqubovilbodfubqo3e8ufbw

Page 48: ELEVATE Paris

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

Page 49: ELEVATE Paris

Apex Remote Action

Static

No View State

Invoked through JS API

Invokes JS Callback

@remoteAction

global static String myMethod(String

inputParam){

...

}

Page 50: ELEVATE Paris

Calling Apex Remote Action

Visualforce.remoting.Manager.invokeAction(’

{!

$RemoteAction.RemoteClass.methodName}',

param,

function(result, event) {

//...callback to handle result

});

Page 51: ELEVATE Paris

Event Object: Success Example

{

"statusCode":200,

"type":"rpc",

"ref":false,

"action":"IncidentReport",

"method":"createIncidentReport",

"result":"a072000000pt1ZLAAY",

"status":true

}

Page 52: ELEVATE Paris

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 53: ELEVATE Paris

Interacting with the Publisher: Allow Submit

Make Submit Active

Payload true/false

Sfdc.canvas.publisher.publish(

{

name: "publisher.setValidForSubmit",

payload:true

});

Page 54: ELEVATE Paris

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 55: ELEVATE Paris

Interacting with the Publisher: Close Publisher Make the Submit Happen

Sfdc.canvas.publisher.publish({name:

"publisher.close", payload:

{ refresh:"true"}});

Page 56: ELEVATE Paris

The Future! (Well, Spring ‘14)

Page 57: ELEVATE Paris

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) {

Page 58: ELEVATE Paris

Canvas

Page 59: ELEVATE Paris

Only has to be accessible from the user’s browser

Authentication via OAuth or Signed Response

JavaScript based SDK Within Canvas, the App can make API

calls as the current user apex:CanvasApp allows embedding

via Visualforce

Any Language, Any Platform

How Canvas Works

Page 60: ELEVATE Paris

OAuth

Page 61: ELEVATE Paris

RemoteApplication

SalesforcePlatform

Sends App Credentials

User logs in,Token sent to callback

Confirms token

Send access token

Maintain session withrefresh token

OAuth2 Authentication Flow

Page 62: ELEVATE Paris
Page 63: ELEVATE Paris

Tools for teams and build masters

Team Development

Page 64: ELEVATE Paris

API to access customizations to the Force.com platform

Metadata API

Page 65: ELEVATE Paris

Access, create and edit Force.com application code

Tooling API

Page 66: ELEVATE Paris

Double-click to enter title

Double-click to enter text

The Wrap Up

Page 67: ELEVATE Paris

Nos prochains évènements à Paris!

Salesforce1 Tour à Paris

Webinar en Français: Data Model & Relationships

Prenez le lead sur notre communauté de Développeurs en France !

Plus d’information sur www.developer.salesforce.com

June 26th

April 29th

A vous de jouer

Page 68: ELEVATE Paris

Questionnaire en ligne

Répondre au questionnaire en ligne sur cet ELEVATE: http://bit.ly/elevateFR

Page 69: ELEVATE Paris

check inbox http://bit.ly/elevateFR

Page 70: ELEVATE Paris

Double-click to enter title

Double-click to enter text

@forcedotcom@pchittum@dcarroll

#forcedotcom#askforce

Page 71: ELEVATE Paris

Double-click to enter title

Double-click to enter text

Join A Developer User Group

http://bit.ly/fdc-dugs

PARIS DUG:http://www.meetup.com/Paris-

Salesforce-Developer-User-Group/

Leader: Mohamed EL MOUSSAOUI

Page 72: ELEVATE Paris

Double-click to enter title

Double-click to enter text

Become A Developer User Group Leader

Email:April Nassi

<[email protected]>

Page 73: ELEVATE Paris

Thank You

Peter ChittumDeveloper Evangelist@[email protected]

Hervé MalevillePlatform [email protected]@salesforce.com