hands-on workshop: introduction to development on force.com for developers

76
Show Flow Dreamforce 2104 Breakout Session Show Flow Template Notes Introduction to Development on Force.com for Developers 2hr 30min Presentation Device: Customer Speaker: Demo Device Deck Owner/Filename: 0:00 Doors open 0:00 Start 5 min 0:05 Welcome and Intros 3 min 0:08 Agenda and workbook 5 min 0:13 Platform Overview 5 min 0:18 Sign up for a DE Please encourage all attendees to sign up for a new DE so they don’t run into any issues with disabled features or API naming issues 25 min 0:43 Writing an Apex Class Here we only have slides, but feel free to show your own use case or demo if you have one 17 min 1:00 Hands-On: Apex 15 min 1:15 SOQL and DML Demo using SOQL in the developer console. Build your own SOQL query and talk it out 15 min 1:30 Hands-On: SOQL/DML 20 min 1:50 Visualforce Demo Twitter bootstrap in VF/yelp demo or your own demo 15 min 2:05 Hands-On: Visualforce 10min 2:15 Controller Extensions 10 min 2:25 Hands-On: Controller Extensions 5 min 2:30 Q&A There is a 30 minute turnaround time in the room, so the Q&A can extend this time if necessary. Also please encourage people to ask questions frequently throughout the day, and to utilize the helpers in the room.

Upload: salesforce-developers

Post on 04-Jul-2015

540 views

Category:

Technology


1 download

DESCRIPTION

Are you an experienced developer who is new to the Salesforce1 Platform? Join us as we introduce you to the fundamentals of Salesforce application development to fast ramp your productivity and shorten your learning curve. You'll learn how to use the key building blocks of the platform: Visualforce Pages to create rich user interfaces, SOQL to access data, and Apex to create classes and database triggers. In this hands-on workshop, you'll use all of these tools to build a complete conference management application that manages sessions, speakers, and speaker assignments. By the end of this workshop, you’ll be ready to start developing your own application productively. Note: This Elevate at Dreamforce Hands-on Workshop is a classroom style hands-on workshop in the DevZone breakout rooms. Please bring your own laptop for the hands-on exercises.

TRANSCRIPT

Page 1: Hands-On Workshop: Introduction to Development on Force.com for Developers

Show FlowDreamforce 2104 Breakout Session Show Flow Template

Notes

Introduction to Development on Force.com

for Developers2hr 30min

Presentation Device:

Customer Speaker:

Demo Device

Deck Owner/Filename:

0:00 Doors open

0:00 Start

5 min 0:05 Welcome and Intros

3 min 0:08 Agenda and workbook

5 min 0:13 Platform Overview

5 min 0:18 Sign up for a DE

Please encourage all attendees to sign up for a new DE so they don’t run into any issues with disabled features or API naming issues

25 min 0:43 Writing an Apex ClassHere we only have slides, but feel free to show your own use case or demo if you have

one

17 min 1:00 Hands-On: Apex

15 min 1:15 SOQL and DML Demo using SOQL in the developer console. Build your own SOQL query and talk it out

15 min 1:30 Hands-On: SOQL/DML

20 min 1:50 Visualforce Demo Twitter bootstrap in VF/yelp demo or your own demo

15 min 2:05 Hands-On: Visualforce

10min 2:15 Controller Extensions

10 min 2:25 Hands-On: Controller Extensions

5 min 2:30 Q&A

There is a 30 minute turnaround time in the room, so the Q&A can extend this time if necessary. Also please encourage people to ask questions frequently throughout the day, and to utilize the helpers in the room.

Page 2: Hands-On Workshop: Introduction to Development on Force.com for Developers

Introduction to Development on Force.comFor Developers Samantha Ready, salesforce.com

Senior Developer Evangelist

@samantha_ready

Page 3: Hands-On Workshop: Introduction to Development on Force.com for Developers

Samantha ReadySenior Developer Evangelist

@samantha_ready

Page 4: Hands-On Workshop: Introduction to Development on Force.com for Developers

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 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 intellectual property and other litigation, 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-Q for the most recent fiscal quarter ended July 31, 2012. This 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 5: Hands-On Workshop: Introduction to Development on Force.com for Developers

Go Social!

@salesforcedevs

Salesforce Developers

+Salesforce Developers

Salesforce Developers

Salesforce Developers

Page 6: Hands-On Workshop: Introduction to Development on Force.com for Developers

Agenda

• Platform Overview

• Writing Apex Classes

• Accessing Data using SOQL

• Writing Triggers

• Writing Visualforce Pages

• Writing Controller Extensions

Extra Credit:

• Using the REST APIs

• Unit Testing

• Batching and Scheduling

Page 7: Hands-On Workshop: Introduction to Development on Force.com for Developers

bit.ly/df14-intro-force

Page 8: Hands-On Workshop: Introduction to Development on Force.com for Developers

Salesforce Platform is the Fastest Path from Idea to App

IdeaBuild App

Idea

buy &

setup

hardware

install

complex

software

define user

access

build & test

security

make it

mobile &

social

setup

reporting &

analytics

build

app

Traditional Platforms

6-12 Months?

App

App

Page 9: Hands-On Workshop: Introduction to Development on Force.com for Developers

Salesforce1 Platform Services

Salesforce1 Platform

Force.com Heroku Exact Target

Salesforce1 Platform APIs

Salesforce1 App

Sales

Cloud

Service

Cloud

Marketing

CloudAppExchange

Custom

Apps

Partner

Apps

Page 10: Hands-On Workshop: Introduction to Development on Force.com for Developers

Salesforce1 Mobile App

• Salesforce on your phone

• Customizable by

– Users

– Admins

– Developers

• Supports

– Objects

– Visualforce

– Canvas

Page 11: Hands-On Workshop: Introduction to Development on Force.com for Developers

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

Page 12: Hands-On Workshop: Introduction to Development on Force.com for Developers

The Conference AppWhat we’ll build…

• Manage sessions and speakers

• Automatically send confirmation emails

• Customized user interface with Visualforce Pages

• Upload speaker pictures

• Flickr integration (Apex) to show conference pictures

Page 13: Hands-On Workshop: Introduction to Development on Force.com for Developers

Free Developer Environment

http://developer.salesforce.com/signup

bit.ly/df14-intro-force

Page 14: Hands-On Workshop: Introduction to Development on Force.com for Developers

Lab 1: Install Your Developer Org

http://developer.salesforce.com/signup

Page 15: Hands-On Workshop: Introduction to Development on Force.com for Developers

Writing Apex Classes

Page 16: Hands-On Workshop: Introduction to Development on Force.com for Developers

What is Apex?

• Salesforce platform language

• Similar to Java

• Object-oriented

• Strongly typed

• Classes and Interfaces

• Cloud based compiling, debugging and unit testing

Page 17: Hands-On Workshop: Introduction to Development on Force.com for Developers

Apex and Java

Same

• Primitive data types

• Flow control (if, for, while, …)

• Exception handling

• Collections: Lists, Sets, …

Different

• Case insensitive

• Single quote strings: 'Joe'

• Id data type

• Built-in support for data access

Page 18: Hands-On Workshop: Introduction to Development on Force.com for Developers

Apex Class

public class MortgageCalculator {

}

public Double amount { get; set; }

public Double rate { get; set; }

public Integer years { get; set; }

public Double calculateMonthlyPayment() {

Integer months = years * 12;

Double monthlyRate = rate / (12 * 100);

return amount * (monthlyRate/

(1 - Math.pow(1 + monthlyRate, -months)));

}

Page 19: Hands-On Workshop: Introduction to Development on Force.com for Developers

Development Tools

• Developer Console

• Force.com IDE (Eclipse Plugin)

• Mavens Mate (Sublime Plugin)

• Force CLI

Page 20: Hands-On Workshop: Introduction to Development on Force.com for Developers

Developer Console

• Browser Based IDE

• Create Classes, Triggers, Pages

• Execute Apex Anonymously

• Execute SOQL Queries

• Run Unit Tests

• Review Debug Logs

Page 21: Hands-On Workshop: Introduction to Development on Force.com for Developers

Lab 4: Creating an Apex Class

• Create the EmailManager class

• Send emails from the developer console

Page 22: Hands-On Workshop: Introduction to Development on Force.com for Developers

Accessing Data with SOQL and DML

Page 23: Hands-On Workshop: Introduction to Development on Force.com for Developers

What's SOQL?

• Salesforce Object Query language

• Similar to SQL

• Streamlined syntax to traverse object relationships

• Built into Apex

• Query results returned as nested objects

Page 24: Hands-On Workshop: Introduction to Development on Force.com for Developers

SELECT Id, Name, Phone

FROM Contact

Page 25: Hands-On Workshop: Introduction to Development on Force.com for Developers

SELECT Id, Name, Phone

FROM Contact

WHERE Phone != null

Page 26: Hands-On Workshop: Introduction to Development on Force.com for Developers

SELECT Id, Name, Phone

FROM Contact

WHERE Phone != null

AND Name LIKE '%rose%'

Page 27: Hands-On Workshop: Introduction to Development on Force.com for Developers

SELECT Id, Name, Phone

FROM Contact

WHERE Phone != null

AND Name LIKE '%rose%'

ORDER BY Name

Page 28: Hands-On Workshop: Introduction to Development on Force.com for Developers

SELECT Id, Name, Phone

FROM Contact

WHERE Phone != null

AND Name LIKE '%rose%'

ORDER BY Name

LIMIT 50

Page 29: Hands-On Workshop: Introduction to Development on Force.com for Developers

Details to Master

SELECT Id, Name, Phone, Account.Name

FROM Contact

WHERE Phone != null

AND Name LIKE '%rose%'

ORDER BY Name

LIMIT 50

Page 30: Hands-On Workshop: Introduction to Development on Force.com for Developers

Master to Details

SELECT Name,

(SELECT FirstName, LastName, Phone

FROM Contacts)

FROM Account

Page 31: Hands-On Workshop: Introduction to Development on Force.com for Developers

Demo: Executing SOQL in the Developer Console

Page 32: Hands-On Workshop: Introduction to Development on Force.com for Developers

Inlining SOQL in Apex

Integer i = [SELECT Count() FROM Session__c];

Page 33: Hands-On Workshop: Introduction to Development on Force.com for Developers

Inlining SOQL in Apex

String level = 'Advanced';

List<Session__c> sessions =

[SELECT Name, Level__c FROM Session__c

WHERE Level__c = :level];

Page 34: Hands-On Workshop: Introduction to Development on Force.com for Developers

Inlining SOQL in Apex

List<String> levels = new List<String>();

levels.add('Intermediate');

levels.add('Advanced');

List<Session__c> sessions =

[SELECT Name, Level__c FROM Session__c

WHERE Level__c IN :levels];

Page 35: Hands-On Workshop: Introduction to Development on Force.com for Developers

Inlining SOQL in Apex

for (Speaker__c s : [select email__c from Speaker__c])

{

System.debug(s.email__c);

}

Page 36: Hands-On Workshop: Introduction to Development on Force.com for Developers

What's DML?

• Data Manipulation Language

• Language used to create, update, delete records

Page 37: Hands-On Workshop: Introduction to Development on Force.com for Developers

insertSession__c session = new Session__c();

session.name = 'Apex 101';

session.level__c = 'Beginner';

insert session;

Page 38: Hands-On Workshop: Introduction to Development on Force.com for Developers

insertSession__c session = new Session__c(

name = 'Apex 201',

level__c = 'Intermediate'

);

insert session;

Page 39: Hands-On Workshop: Introduction to Development on Force.com for Developers

updateString oldName = 'Apex 101';

String newName = 'Apex for Beginners';

Session__c session =

[SELECT Id, Name FROM Session__c

WHERE Name=:oldName];

session.name = newName;

update session;

Page 40: Hands-On Workshop: Introduction to Development on Force.com for Developers

deleteString name = 'Testing 501';

Session__c session =

[SELECT Name FROM Session__c

WHERE Name=:name];

delete session;

Page 41: Hands-On Workshop: Introduction to Development on Force.com for Developers

Lab 5: Accessing Data using SOQL and DML

• Execute SOQL statements in the Query Editor

• Execute DML statements in the Anonymous Window

Page 42: Hands-On Workshop: Introduction to Development on Force.com for Developers

Writing Triggers

Page 43: Hands-On Workshop: Introduction to Development on Force.com for Developers

What's a Trigger?

• Apex code executed on database events

• Before or after:

– Insert

– Update

– Delete

– Undelete

Page 44: Hands-On Workshop: Introduction to Development on Force.com for Developers

Before or After?

• Before

– Update or validate values before they are saved to the database

– Example: Prevent double-booking of a speaker

• After

– Need access to values set by the database (Id, lastUpdated, …)

– Example: Send speaker confirmation email

Page 45: Hands-On Workshop: Introduction to Development on Force.com for Developers

Bulk Mode

• Trigger API is designed to support bulk operations

– Data Import, Bulk API, etc.

• Triggers work on bulk of records, not single records

• Context variables provide access to data:

– Trigger.old and Trigger.new (List)

– Trigger.oldMap and Trigger.newMap (Map)

Page 46: Hands-On Workshop: Introduction to Development on Force.com for Developers

Example 1trigger WelcomeKit on Account (after insert) {

List<Case> myCases = new List<Case>();

for (Account account : Trigger.new) {

Case welcomeCase = new Case();

welcomeCase.Subject = 'Mail Welcome Kit';

welcomeCase.AccountId = account.Id;

myCases.add(welcomeCase);

}

insert myCases;

}

Page 47: Hands-On Workshop: Introduction to Development on Force.com for Developers

Example 2

Trigger on Account (before update) {

for (Account acc: Trigger.New) {

// Compare new value with old value

if (acc.Rating != Trigger.oldMap.get(acc.Id).Rating) {

// Your Logic

}

}

}

Page 48: Hands-On Workshop: Introduction to Development on Force.com for Developers

Workflow vs Trigger

Workflow Trigger

Created with Clicks Code

What can it do • Update field

• Send email

• Create task

• Send outbound message

• Launch flow (flow trigger)

~ Anything (e.g.

create/delete records, REST

callout, etc.)

Cross-object field updates Limited (detail -> master) Any

Page 49: Hands-On Workshop: Introduction to Development on Force.com for Developers

Lab 6: Writing Triggers

• Write the SendConfirmationEmail trigger

• Write the RejectDoubleBooking trigger

Page 50: Hands-On Workshop: Introduction to Development on Force.com for Developers

Writing VisualforcePages

Page 51: Hands-On Workshop: Introduction to Development on Force.com for Developers

What's a Visualforce Page?

• HTML page with tags executed at the server-side to generate dynamic content

• Similar to JSP and ASP

• Can leverage JavaScript and CSS libraries

• The View in MVC architecture

Page 52: Hands-On Workshop: Introduction to Development on Force.com for Developers

Model-View-Controller

ModelData + Rules

ControllerView-Model

interactions

ViewUI code

Separation of concerns

– No data access code in view

– No view code in controller

Benefits

– Minimize impact of changes

– More reusable components

Page 53: Hands-On Workshop: Introduction to Development on Force.com for Developers

Model-View-Controller in Salesforce

View• Metadata

• Standard Pages

• Visualforce Pages

• External apps

Controller• Metadata

• Standard Controllers

• Controller Extensions

• Custom Controllers

Model• Metadata

• Objects

• Triggers (Apex)

• Classes (Apex)

Page 54: Hands-On Workshop: Introduction to Development on Force.com for Developers

Expression Language

• Anything inside of {! } is evaluated as an expression

– Dynamic variables: {!Contact.Phone} or {!myApexVariable}

– Logic: {! IF (Opportunity.Stage == ‘Closed/Won’, val_if_true, val_if_false)}

– Functions: {!JSENCODE(Account.BillingAddress)}

• Same expression language as Formulas

• $ provides access to global variables (User, Page, RemoteAction, Resource, …)

– {! $User.FirstName } {! $User.LastName }

Page 55: Hands-On Workshop: Introduction to Development on Force.com for Developers

Example 1<apex:page>

<h1>Hello, {!$User.FirstName}</h1>

</apex:page>

Page 56: Hands-On Workshop: Introduction to Development on Force.com for Developers

Example 2

<apex:page standardController="Contact">

<apex:form>

<apex:inputField value="{!contact.firstname}"/>

<apex:inputField value="{!contact.lastname}"/>

<apex:commandButton action="{!save}" value="Save"/>

</apex:form>

</apex:page> Function in

standard controller

Standard controller

object

Page 57: Hands-On Workshop: Introduction to Development on Force.com for Developers

Standard Controller

• A standard controller is available for all objects

– You don't have to write it!

– No test methods needed

– Can grab a single record or set of records

• Provides standard CRUD operations

– Create, Update, Delete, Field Access, etc.

• Can be extended with more capabilities (next module)

• Uses id query string parameter in URL to access object

Page 58: Hands-On Workshop: Introduction to Development on Force.com for Developers

Component Library

• Presentation tags

– <apex:pageBlock title="My Account Contacts">

• Fine grained data tags

– <apex:outputField value="{!contact.firstname}">

– <apex:inputField value="{!contact.firstname}">

• Coarse grained data tags

– <apex:detail>

– <apex:pageBlockTable>

• Action tags

– <apex:commandButton action="{!save}" >

Page 59: Hands-On Workshop: Introduction to Development on Force.com for Developers

Demo: Dissect a Visualforce Page & Build with Bootstrap

Page 60: Hands-On Workshop: Introduction to Development on Force.com for Developers

Email

Templates

Embedded in Page

Layouts

Generate PDFs

Custom Tabs Mobile

Interfaces

Page Overrides

Where can I use Visualforce?

Page 61: Hands-On Workshop: Introduction to Development on Force.com for Developers

Lab 7: Writing Visualforce Pages

• Write the SpeakerForm Visualforce page

• Set it as default for creating and editing speakers

Page 62: Hands-On Workshop: Introduction to Development on Force.com for Developers

Writing Controller Extensions and Custom Controllers

Page 63: Hands-On Workshop: Introduction to Development on Force.com for Developers

What's a Controller Extension?

• Custom class written in Apex

• Works on the same object as the standard controller

• Can override standard controller behavior

• Can add new capabilities

Page 64: Hands-On Workshop: Introduction to Development on Force.com for Developers

Defining a Controller Extension

<apex:page standardController="Speaker__c"

extensions="SpeakerCtrlExt, ext2">

Provides basic

CRUD

Overrides standard

actions and/or provide

additional capabilities

Page 65: Hands-On Workshop: Introduction to Development on Force.com for Developers

Anatomy of a Controller Extensionpublic class SpeakerCtrlExt {

private final Speaker__c speaker;

private ApexPages.StandardController stdController;

public SpeakerCtrlExt (ApexPages.StandardController ctrl) {

this.stdController = ctrl;

this.speaker = (Speaker__c)ctrl.getRecord();

}

// method overrides

// custom methods

}

Page 66: Hands-On Workshop: Introduction to Development on Force.com for Developers

Demo: Dissect a Controller Extension

Page 67: Hands-On Workshop: Introduction to Development on Force.com for Developers

What's a Custom Controller?

• Custom class written in Apex

• Doesn't work on a specific object

• Provides custom data

• Provides custom behaviors

Page 68: Hands-On Workshop: Introduction to Development on Force.com for Developers

Defining a Custom Controller

<apex:page controller="FlickrController">

Page 69: Hands-On Workshop: Introduction to Development on Force.com for Developers

Custom Controller Example

public with sharing class FlickrController {

public FlickrList getPictures() {

HttpRequest req = new HttpRequest();

req.setMethod('GET');

req.setEndpoint('http://api.flickr.com/services/feeds/');

HTTP http = new HTTP();

HTTPResponse res = http.send(req);

return (FlickrList) JSON.deserialize(res.getBody(),

FlickrList.class);

}

}

Page 70: Hands-On Workshop: Introduction to Development on Force.com for Developers

Lab 8: Writing a Controller Extension

• Write a Controller Extension that supports Picture Upload

Page 71: Hands-On Workshop: Introduction to Development on Force.com for Developers

Surveybit.ly/df-how-introforce

Samantha Ready

Senior Developer Evangelist

@samantha_ready

Page 72: Hands-On Workshop: Introduction to Development on Force.com for Developers
Page 73: Hands-On Workshop: Introduction to Development on Force.com for Developers

Certification Logos for “Speaker Intro Slides”

For salesforce.com

use only

Guides for logo placement

Page 74: Hands-On Workshop: Introduction to Development on Force.com for Developers

Column title Column title Column title Column title

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

Example of a TableTable subtitle

Page 75: Hands-On Workshop: Introduction to Development on Force.com for Developers

Column title Column title Column title Column title

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

0.00 0.00 0.00 0.00

Example of a TableTable style and coloring

Page 76: Hands-On Workshop: Introduction to Development on Force.com for Developers

Device Family Without Screens