Escolar Documentos
Profissional Documentos
Cultura Documentos
com (Visualforce)
Pages
Force.com
LY
N
O
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
SE
All rights reserved. Various trademarks held by their respective owners.
U
AL
N
R
TE
IN
This document contains proprietary information of salesforce.com, inc., it is provided under a license
agreement containing restrictions on use, duplication and disclosure and is also protected by copyright
law. Permission is granted to customers of salesforce.com, inc. to use and modify this document for their
internal business purposes only. Resale of this document or its contents is prohibited.
The information in this document is subject to change without notice. Should you find any problems or
errors, please log a case from the Support link on the Salesforce home page. Salesforce.com, inc. does
not warrant that this document is error- free.
"Salesforce.com" and the "no software" logo are registered trademarks of salesforce.com, inc. Other
names used may be marks of their respective owners.
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions.
If any such uncertainties materialize or if any of the assumptions prove 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-
lookingg statements, including:
g anyypprojections
j of earnings,
g revenues, or other financial items; anyy statements
regarding strategies or plans of management for future operations; any statements concerning new, planned,
or upgraded services or developments; statements about current or future economic conditions; and any
statements of belief.
The risks and uncertainties referred to above include but are not limited to risks associated with 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 immature market in which
we operate; our relatively limited operating history; our ability to expand, retain, and motivate our employees
and manage our growth; risks associated with new releases of our service; and risks associated with selling
to larger enterprise customers. Further information on potential factors that could affect the financial results
LY
of salesforce.com, inc. are included in our registration statement (on Form S-1) and in other filings with the
S iti and
Securities d Exchange
E h C i i
Commission. Th
These d
documents t are available
il bl on th
the SEC Fili ti off th
Filings section the
salesforce.com website.
N
Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Any unreleased services or features referenced in this or other press releases or public statements are not
O
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.
SE
Copyright 2010 salesforce.com, inc. 3
U
AL
N
Course Objectives
R
Visualforce pages.
Create custom pages that mimic the standard Salesforce
presentation style using standard tags while altering the
content presented.
Use the expression syntax to bind data and actions on a page
t a controller.
to t ll
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 5
U
AL
N
Course Agenda
R
Introduction to Visualforce
TE
Visualforce Components
Basic Page Components
IN
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 7
U
AL
N
Module 1:
R
Introduction to
TE
Visualforce
IN
Visualforce Pages
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
Objects
Data Web Services API
LY
Fields Model Metadata API
R l ti hi
Relationships
N
Declarative Programmatic
O
Simplicity + Speed SE Control + Flexibility
Copyright 2010 salesforce.com, inc. 9
U
AL
N
Module Objectives
R
Visualforce Overview
Visualforce Basics
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 11
U
AL
N
Any application
Any user interface
Any device
Limited/no
Full control of
control of UI
UI behavior
behavior
LY
Li it d control
Limited t l over
look and feel, but all Full pixel level
N
UIs are consistent control over UI
O
Page Builder SE
Copyright 2010 salesforce.com, inc. 13
U
AL
N
Visualforce
R
LY
Access to the inline
editor is available only
in Development Mode.
N
Visualforce pages can
also be edited through
O
the Force.com IDE.
SE
Copyright 2010 salesforce.com, inc. 15
U
AL
N
Visualforce Content
R
Force.com expressions.
HTML.
JavaScript.
Flash.
Any other code that can execute within an HTML page on Force
Force.com.
com
Visualforce pages can have up to 1 MB of content and can bring back
up to 15 MB.
LY
and simplifies
p development.
p
To view the resulting code from any Visualforce page, right-click the
N
page and select View Source.
O
SE
Copyright 2010 salesforce.com, inc. 17
U
AL
N
View State
R
LY
Visualforce pages are automatically upgraded to the next Salesforce release.
Visualforce separates the view of information from the navigation control and
N
the data model.
It conforms to the Model-View-Controller development pattern.
O
SE
Copyright 2010 salesforce.com, inc. 19
U
AL
N
Model
State State
Query Change
Change
Notification
View
Selection
View Controller
User Manages the
interface User interactions
Gestures
details between view
& model
View
Vie Opportunity overview page
Opportunity list views page
Opportunity detail page
Opportunity edit page List View
Opportunity Product detail page
Opportunity Product multi-line edit page
LY
View links detail p
page
g
New button edit page
Edit buttons & links edit page
N
Save button save action
Delete buttons & links delete action Edit Page
O
SE
Copyright 2010 salesforce.com, inc. 21
U
AL
N
Detail / Edit
Page
IN
Hard-wired representation
of data model
Detail sections (parent)
Related lists (children)
Limited layout options
1 or 2 column
l d
details
t il
Related lists at bottom
Detail & edit page share
1 layout
View link
Delete
action
Cl
Clone
View
action
link
Overview List View Detail Page
List
View
picker
Edit
LY
button
Edit Page
Save
S
action
N
O
New button
SE
Copyright 2010 salesforce.com, inc. 23
U
AL
N
Model
Model View Controller
TE
What schema and data How is the user How are the user
does the app use? interface and data interface actions and
presented? logic represented?
IN
Standard &
Standard &
Pages Custom
Custom Objects
Controllers
Controller
Components
Extensions
Visualforce Overview
Visualforce Basics
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 25
U
AL
N
LY
Built-in AJAX functionalityy
supporting partial page refresh
N
Over 65 components at GA
Accessed through <apex:tag>
O
SE syntax
Visualforce
TE
component
tag
<apex:pageBlockSection title="Contact Information">
<apex:inputField value="{!contact.firstname}"/>
IN
<apex:inputField value="{!contact.salutation}"/>
<apex:inputField value="{!contact.lastname}"/>
</apex:pageBlockSection>
data
binding
expression
LY
components that call data or
actions.
Controller can be used to
N
maintain state across page
O
interactions (in wizards, for
example).
SE
Copyright 2010 salesforce.com, inc. 30
U
AL
N
Standard Controllers:
TE
Custom Controllers:
Are coded to create custom behaviors or non-standard data sets.
Can be used to create wizards or leverage callouts
callouts.
Are invoked by using:
<apex:page controller=MyController>
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 32
U
AL
N
Controller Extensions:
TE
standardController=Contact extensions=MyClass,
MyOtherClass>
Visualforce uses the expression syntax (also found in merge fields and
formulas) to bind components to Salesforce data and actions in the
pages controller.
All content in {!...} will be evaluated as an expression.
{!$User.FirstName} shows the current users first name in a page.
Data context is provided to controllers by the ID parameter, just as in
standard pages.
https://na1.salesforce.com/myPage?id=001000000007Erj
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 34
U
AL
N
Versioning
R
LY
p y with custom tags
displayed g instead of the letter c.
Example:<thirdpartycompany:customtag>
N
thirdpartycompany is the namespace
O
SE
Copyright 2010 salesforce.com, inc. 36
U
AL
N
BEHAVIOR
Standard Custom
EL
LOOK AND FEE
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 38
U
AL
N
Goal:
45 min.
TE
LY
pages? When does it become necessary?
N
O
SE
Copyright 2010 salesforce.com, inc. 40
U
AL
N
Module 2:
R
Visualforce
TE
Components
C p
IN
Visualforce Pages
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
41
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 42
U
AL
N
Module Agenda
R
Components
TE
Component Bindings
IN
LY
Note: You cannot use JavaScript line commenting except within <script>
tags.
N
O
SE
Copyright 2010 salesforce.com, inc. 44
U
AL
N
Every Visualforce start tag <tagName> must have a matching end tag
</tagName> or be a self contained tag <tagName/>.
Tags are hierarchical and must be closed in the reverse order they
IN
were opened.
<tagName1>
<tagName2>
</tagName2>
</tagName1>
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 46
U
AL
N
Components Example
R
TE
component
namespace component tag attribute
name attribute value comment
start tag
IN
<apex:page title=myPage>
<!- This is a comment -->
Visualforce //This is not. This is just text
component (tag) <h1>Congratulations</h1> <p/>
This is your new Page: myNewPage
</apex:page>
/
end tag self-contained tag
Components
Component Bindings
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 48
U
AL
N
Component Bindings
R
Data bindings: using the expression syntax to pull in data from the
data set made available by the page controller.
Action bindings: using the expression syntax to call action methods
for functions coded in the page controller.
Component bindings: using component attribute values to reference
other components IDs.
These other components must have set a value for the id attribute.
Visualforce
component
tag
<apex:pageBlockSection title="Contact Information">
<apex:inputField value="{!contact.firstname}"/>
<apex:inputField value="{!contact.salutation}"/>
<apex:inputField value="{!contact.lastname}"/>
</apex:pageBlockSection>
data
binding
expression
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 50
U
AL
N
Tags use the same expression syntax as formula fields and other areas of the
application.
Dynamic object data can be inserted using the
{! bj tN
{!objectName.propertyName}
t N } syntax.
t
Global data can be inserted with the added $ syntax, such as:
{!$User.fieldName}
{!$Page.otherVisualforcePage}
{!$Component.otherVisualforceComponent}
LY
Note that you can also access custom labels and translations using the
variable
$Label variable.
Local variables can be created to stand in for these expressions, as they can
N
become long and unwieldy using the <apex:variable> tag.
Bindings can reference custom Apex class types as well as their inner classes
O
using dot notation. SE
Copyright 2010 salesforce.com, inc. 52
U
AL
N
1 <apex:page standardController="Account">
TE
Data binding works because the page can access the data made
available through the controller.
In a similar manner, actions that are available through
g the controller can
be called using the same expression syntax. These can be:
Standard actions, such as save and edit.
Custom actions that provide custom functionality.
More on this later in the discussion about controllers. Note that at
this point, only actions that are the shared across all objects are
LY
exposed through standard controllers.
N
O
SE
Copyright 2010 salesforce.com, inc. 54
U
AL
N
page is rendered.
The tag can be referenced by the ID by other tags, JavaScript, or
other Web-enabled languages.
Salesforce recommends using unique IDs within each page.
If not unique, you may need to specify the hierarchy of IDs to locate
the correct component
component.
The hierarchy prevents the possibility of duplicate IDs on HTML
elements generated by components.
However, raw HTML could produce dupes.
Example:
1 <apex:page id="thePage">
2 <!-- The following script element contains a simple function for changing the
3 font. -->
4 <script>
5 function changeFont(input, textid) {
6 if(input.checked) document.getElementById(textid).style.fontWeight =
7 "bold";
8 else document.getElementById(textid).style.fontWeight = "normal";
9 }
10 </script>
11 <!-- The first outputPanel calls the function, passing in the existing occurrence
12 of the checkbox, as well as the DOM ID of the output component. -->
13 <apex:outputPanel layout="block">
14 <label for="checkbox">Click this box to change text font: </label>
LY
15 <input id="checkbox" type="checkbox"
onclick="changeFont(this
onclick= changeFont(this,'{!$Component thePanel}');"/>
{!$Component.thePanel} ); />
16 </apex:outputPanel>
17 <!-- The second outputPanel contains the text that will be changed. -->
N
18 <apex:outputPanel id="thePanel" layout="block">Change me!
19 </apex:outputPanel>
20 </apex:page>
O
SE
Copyright 2010 salesforce.com, inc. 56
U
AL
N
Goal:
15 min.
TE
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 58
U
AL
N
Module 3: Basic
R
TE
Page Components
IN
Visualforce Pages
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
59
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 60
U
AL
N
Module Agenda
R
Core Components
TE
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 62
U
AL
N
<apex:page>
R
TE
IN
<apex:page>
LY
page
page.
sidebar (Boolean): whether the sidebar should be used (default=true).
N
action (Action method): invokes an action method on the controller to be
O
run when the page is first requested.
renderAs (String): a supported content converter (currently only pdf).
SE
Copyright 2010 salesforce.com, inc. 64
U
AL
N
<apex:variable/>
R
Attributes include:
value (Object): an expression that can be represented by the new
variable.
var (String): the name of the new variable.
Static resources are a new kind of Salesforce storage, designed for use
with Visualforce.
Static resources are items required by your Visualforce pages, such as
archi es images
archives, images, st
style
le sheets
sheets, Ja
JavaScript
aScript ffunctions,
nctions PDFs
PDFs, etc
etc.
These resources can be referenced using the $Resource global
variable.
They can be a collection of related files into a directory hierarchy
(.zip, .jar).
This is the recommended method over uploading these files to the
LY
Document tab, as these resources can be cached for better
performance
performance.
Upload files via Your Name | Setup | Develop | Static Resources.
N
There is a 5 MB limit per file and a 250 MB overall limit for static
O
resources.
SE
Copyright 2010 salesforce.com, inc. 66
U
AL
N
<apex:image>
<apex:stylesheet>
These can be stored in the Static Resources object or elsewhere on
the Internet.
You can also use the action attribute on the page component to
redirect to a static resource, such as a custom help PDF file:
action={!URLFOR($Resource.filename)}>
1 <apex:page sidebar=false showHeader=false standardStylesheets=false
action={!URLFOR($Resource.filename)}>
2 </apex:page>
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 68
U
AL
N
Style Sheets
R
Core Components
Default Look and Feel Components
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 70
U
AL
N
<apex:pageBlock>
R
There are a series of pageBlock tags that help build out pages and use
TE
<apex:sectionHeader>
<apex:pageBlockSection>
<apex:pageBlock>
<apex:pageBlockSectionItem>
This tag creates an area of a page that is similar to a detail page but
with no default content.
Attributes include:
mode (String): either detail or edit mode. Edit mode does not
show field lines. (detail)
title (String): title displayed on the page block.
tabStyle (String): Salesforce object used to copy the color and
style for this page block.
LY
The pageBlock tags can include facet tags, which are child tags that
are often used to add or override headers and footers to areas or
N
tables.
O
SE
Copyright 2010 salesforce.com, inc. 72
U
AL
N
<apex:pageBlockButtons>
R
This tag creates a set of buttons that are styled like standard
TE
Salesforce buttons.
The individual buttons are created using the commandButton tag.
Attributes include:
IN
LY
columns (Integer): number of columns
columns, each with two cells
cells. (2)
N
O
SE
Copyright 2010 salesforce.com, inc. 74
U
AL
N
<apex:pageBlockSectionItem>
R
Each column has two cells: one for the label and one for the value.
These can be added with outputLabel tags and inputText or other UI
widget components.
If you need to bundle more than one item per cell, wrap them in an
<apex:outputPanel> component.
This tag creates the standard header bar displayed under the tabs in
the Salesforce UI.
Attributes include:
title (String): the text displayed at the top of the bar.
subtitle (String): the text displayed under the title.
help (String): the URL for the pages help file. The link appears on
the right.
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 76
U
AL
N
Other UI Features
R
There are a variety of other tags that can be used to create standard Web
TE
LY
<apex:panelGrid> & <apex:panelGroup>
Place items into an HTML grid.
N
Use groups to place multiple items in the same cell.
O
Does not process a set of data with an iteration variable.
SE
Copyright 2010 salesforce.com, inc. 78
U
AL
N
Goal:
10 min.
TE
Scenario:
Universal Containers wants to get a basic understanding for
Visualforce components by seeing what it would take to re-
create a detail page bit by bit. In particular, the company needs
help with the layout components for the page.
Tasks:
Add the pre-existing Visualforce page to your org and test it
with an existing position.
LY
Although,
g , it is possible
p to build up
p identical sections using
g finer
metadata and layout components.
N
O
SE
Copyright 2010 salesforce.com, inc. 80
U
AL
N
<apex:detail/>
R
This single tag creates the standard detail page layout for this object.
TE
Attributes include:
subject (String): the ID of the record that should provide the data
IN
This single tag creates just the related list for records related to a
parent record.
Attributes include:
list (String): the name of the child relationship from which to return
the records.
subject (String): the ID of the record that should provide the data
for the related list.
pageSize (Integer): the number of records to display by default. (5)
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 82
U
AL
N
<apex:listViews/>
R
This single tag creates the list view picklist for an object, usually
TE
type (String): the object for which list views are displayed.
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 84
U
AL
N
Chatter tags
R
This tag simply iterates over the data of a collection for a structure that
you specify.
It is typically
yp y used if one of the other iteration components
p does not
meet the requirements.
Attributes include:
value (Object): references the collection of data.
rows (Integer): the number of items in the collection that are
rendered. (0 = all rows)
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 86
U
AL
Message Components
N
R
There are also pagemessage and pagemessages tags that use the standard
Salesforce style.
Use this tag to display messages, such as validation errors, to users that are
usually available through the standard Salesforce UI.
Attributes include:
for (String): ID of the component with which the label should be associated.
title (String): the text displayed next to the output link.
style (String): the style used to display the component.
tooltip (Boolean): specifies whether the detail portion of the message is displayed
as a tooltip. (false)
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 88
U
AL
N
Output Components
IN
Visualforce Pages
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
89
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 90
U
AL
N
Module Agenda
R
Form Components
TE
LY
the form is submitted; possible values include _blank,
blank _parent,
parent
_self, and _top.
N
O
SE
Copyright 2010 salesforce.com, inc. 92
U
AL
N
<apex:inputField>
R
These tags provide input widgets for data that does not correspond to a
Salesforce object field to be used with pageBlockSectionItem tags.
These include:
<apex:inputCheckbox>
<apex:inputHidden> (useful for passing variables between
pages)
<apex:inputSecret> (for masked data, such as passwords)
<apex:inputText>
LY
<apex:inputTextarea> (includes an attribute to specify saving
the text as plain text or rich text)
N
O
SE
Copyright 2010 salesforce.com, inc. 94
U
AL
<apex:inputWidget> (cont.)
N
R
In general, these tags include attributes that give you ways to:
TE
LY
These work with the Apex SelectOption object to specify the values
in custom controllers.
N
O
SE
Copyright 2010 salesforce.com, inc. 96
U
AL
N
<apex:inputFile>
R
This tag allows users to upload files and turn them into:
TE
Attachments on records.
Documents.
Documents
IN
Apex Blobs.
Attributes include:
accept (String): a comma-separated list of file types accepted
for upload.
contentType (String): the uploaded files content type.
fileName (String):
(St i ) ththe name off th
the uploaded
l d d fil
file.
These tags create buttons and links that allow the users to navigate
and take actions.
These tags must be used within a form tag.
Attributes include:
action (Action Method): references through merge-field syntax a
method on the controller. Standard controllers support {!save},
{!edit}, and {!delete}.
Buttons for standard controllers are not rendered for users that do
LY
not have the appropriate permissions.
value (String): text displayed on the button or link.
The <apex:param> tag can be used to dynamically add URL
N
parameters to a link.
O
SE
Copyright 2010 salesforce.com, inc. 98
U
AL
N
Module Agenda
R
Form Components
TE
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 100
U
AL
N
<apex:outputLabel>
R
This tag creates a label for input or output widgets that do not
TE
LY
Tasks:
Add the pre-existing Visualforce page to your org.
Override the Review Edit button.
N
Test the page.
O
SE
Copyright 2010 salesforce.com, inc. 102
U
AL
N
15 min.
TE
selectRadio
outputLabel
selectOption
outputField
IN
inputField
outputLabel selectRadio
selectOption
outputLabel
inputTextarea
selectList
outputLabel
selectOption
outputLabel
inputTextarea
inputField
inputField
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 104
U
AL
N
<apex:outputLink>
R
Attributes include:
value (String): the URL used for the link.
Use with the $Page expression to access other Visualforce pages.
title (String): the text displayed next to the output link.
coords ((Integer):
g ) the p
position and shape
p of the hot spot
p for the link if
used with an image.
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 106
U
AL
N
<apex:outputPanel>
R
This tag defines a set of content that is grouped together, often for the
TE
This tag simply displays text that can be formatted using a style sheet.
Text can be used with nested param tags to dynamically insert data.
Attributes include:
value (String): the text that is displayed.
title (String): the text displayed next to the output link.
style (String): the style used to display the component.
escape (Boolean): specifies whether sensitive HTML or XML
characters should be escaped. (true)
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 108
U
AL
<apex:outputText> (cont.)
N
R
This tag creates a table by iterating over a set of data using the default
Salesforce style sheet.
It can be used within either a pageBlock or a pageBlockSection.
Use the column tag to specify the tables columns.
If you specify a Salesforce object field for a column, the associated
label is automatically used in the header.
You can alternatively use the <apex:dataTable> or
<apex:dataList> tags if the data is not being supplied by a
Salesforce object or you wish to use a different style sheet.
LY
Attributes include:
columns (Integer): number of columns in the table.
N
value (Object): references the collection of data, usually in the form
of a merge field that references Salesforce object in the form of
O
{!object}.
SE
Copyright 2010 salesforce.com, inc. 110
U
AL
N
<apex:dataList>
R
data.
As there is onlyy one column, the bodyy of the tag
g specifies
p how a single
g
item should appear in the list.
IN
Attributes include:
value (Object): the collection of data displayed in the list.
type (String): the type of list to display. For ordered lists, possible
values are: 1, a, A, i, I. For unordered lists: disc, square,
circle. (disc)
rows (Integer): the number or rows to display. (0 = all rows)
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 112
U
AL
N
<apex:column/>
R
LY
Tasks:
Create the new Visualforce page.
Add the page to an inline section of the page layout.
N
Test the page.
O
SE
Copyright 2010 salesforce.com, inc. 114
U
AL
N
Flash
R
Flash code is compiled into .swf files that can be embedded into Web
TE
Notice that this tag includes the name of the file, the dimensions of how
it should be displayed, and a list of name/value pairs of parameters.
Yo
You ma
may not have
ha e access to the flash so
source
rce code
code, so it is important
that you understand the name/value pairs that are expected.
LY
flashVars="startValue={!field}&min=1&max=5&snapInterval=1&callbac
kFunction=updateHiddenValue&passthroughId={!$Component.theForm.re
viewBlock.scores.hiddenfieldId}&bgColor=#F3F3EC"
N
src="{!$Resource.flashSlider}" height="40" width="175" />
O
SE
Copyright 2010 salesforce.com, inc. 116
U
AL
N
<apex:facet>
R
Attributes include:
name (String): describes if the facet is a header, footer, or
caption.
1 ...
2 <apex:pageBlocktable value="{!partnercerts}" var="p" id="partnerlist">
3 <apex:column>
4 <apex:facet name="header">
5 <apex:commandLink
value="{!$ObjectType.Indvidual__c.Fields.First_Name__c.Label}"
action="{!sortPartners}" >
6 <apex:param name="sortColumn" value="first_name__c"
assignTo="{!sortColumn}"/>
7 </apex:commandLink>
8 </apex:facet>
9 {!p.partner.First_Name__c}
10 </apex:column>
11
2 Copyright 2010 salesforce.com, inc. 117
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 118
U
AL
N
Module 5: Visualforce
R
Components for
TE
Modularity
IN
Visualforce Pages
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
119
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 120
U
AL
N
<apex:component>
R
Components.
Custom components can be accessed using the c namespace (as in
<c:componentname>, and are automatically added to the online
reference.
Attributes include:
controller or extensions (String): name of the controller that
used to control the behavior of this component.
access (String): indicates the ability to use the component outside
of the same namespace.
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 122
U
AL
N
Goal:
15 min.
TE
LY
Add the slider flash file to yyour static resources.
Add the pre-existing Visualforce page to your org.
N
Override the Review Edit button.
O
Test the page.
SE
Copyright 2010 salesforce.com, inc. 124
U
AL
N
Page Inclusions
R
iframe.
<apex:iframe>: insert Web content using a URL.
IN
Target1.page
StdFooter1.page
<apex:include />
Target1 Page
1 <apex:page showHeader=false>
2 Unique content for this page.
LY
3 <apex:include pageName="{!$Page.StdFooter1}" />
4 </apex:page>
/ape :page
N
StdFooter1 Page
1 <apex:page >
O
2 <br />
3 <i>This is the standard footer.</i>
4 </apex:page> SE
Copyright 2010 salesforce.com, inc. 126
U
AL
N
Template Tags
R
Target2.page Template1.page
<apex:composition >
<apex:insert name=headerTitle>
<apex:define name=headerTitle>
Target2 Page
1 <apex:page showHeader="false" >
2 <apex:composition template="{!$Page.Template1}" >
LY
3 <apex:define name="headerTitle">Products</apex:define>
4 <apex:define
p name="body">Unique
y q content for this page.<br/></apex:define>
p g p
5 </apex:composition>
6 </apex:page>
N
Template1 Page
O
1 <apex:page >
2 Welcome to the <b><apex:insert name="headerTitle" /></b> page.<br/>
3 <apex:insert name="body" />
4 </apex:page>
SE
Copyright 2010 salesforce.com, inc. 128
U
AL
Templates
R
Goal:
10 min.
TE
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 131
U
AL
N
Module 6:
R
JavaScript in
TE
Visualforce
IN
Visualforce Pages
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
132
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 133
U
AL
N
Module Agenda
R
JavaScript Functions
Partial Page Updates
IN
At this point, only actions that are shared across all objects are exposed
through standard controllers.
But further standard Salesforce actions are available by using JavaScript and
th expression
the i syntax
t with
ith the
th !URLFOR and d $Action
$A ti k
keywords.
d
Additional standard actions will be added into standard controllers in future
releases.
See the online help for more information regarding global $ variables.
Example:
1 <apex:pageBlockButtons>
LY
2 <apex:commandButton value="Edit" action="{!edit}"/>
3 <apex:commandButton
ape :co a d utto
4 onclick="parent.window.location.href='{!URLFOR($Action.Position__c.Clone,position.id)
}'" value="Clone"/>
5 </apex:pageBlockButtons>
N
O
SE
Copyright 2010 salesforce.com, inc. 135
U
AL
N
Module Agenda
R
JavaScript Functions
Partial Page Updates
IN
LY
Example: onclick=changeFont();
It can also be useful to isolate the JavaScript at the top of the page for
maintenance purposes.
N
O
SE
Copyright 2010 salesforce.com, inc. 137
U
AL
N
Example:
TE
1 <apex:page id="thePage">
2 <!-- The following script element contains a simple function for changing the
3 font. -->
4 <script language="JavaScript" type="text/javascript">
5
IN
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 139
U
AL
N
LY
Add the reRender attribute to the button or link tag and assign it the
value of the id of the outputPanel
t tP l created earlier
earlier.
N
O
SE
Copyright 2010 salesforce.com, inc. 141
U
AL
N
Example:
TE
IN
1 <apex:page standardController="Account">
2 <apex:pageBlock title="Hello {!$User.FirstName}!">
3 You are displaying contacts from the {!account.name} account.
4 Click a contact's name to view his or her details.
5 </apex:pageBlock>
6 <
<apex:pageBlock
Bl k title="Contacts">
titl "C t t ">
7 <apex:form >
8 <apex:dataTable value="{!account.Contacts}" var="contact" cellPadding="4"
border="1">
9 <apex:column >
10 <apex:commandLink rerender="detail">
11 {!contact.Name}
12 <apex:param name="cid" value="{!contact.id}"/>
13 </apex:commandLink>
14 </apex:column>
15 </apex:dataTable>
LY
16 </apex:form>
17 </apex:pageBlock>
p p g
18 <apex:outputPanel id="detail">
19 <apex:detail subject="{!$CurrentPage.parameters.cid}" relatedList="false"
title="false"/>
N
21 </apex:outputPanel>
22 </apex:page>
O
SE
Copyright 2010 salesforce.com, inc. 143
U
AL
N
Module Agenda
R
JavaScript Functions
Partial Page Updates
IN
LY
<apex:facet name stop > tags.
name=stop>
N
O
SE
Copyright 2010 salesforce.com, inc. 145
U
AL
N
1 <apex:page standardController="Account">
2
TE
8 </apex:commandLink>
9 </apex:column>
10 </apex:dataTable>
11 </apex:form>
12 </apex:pageBlock>
13 <apex:outputPanel id="detail">
14 <apex:actionStatus startText="Requesting...">
15 <apex:facet name="stop">
16 <apex:detail subject="{!$CurrentPageReference.parameters.cid}"
relatedList="false" title="false"/>
17 </apex:facet>
p
18 </apex:actionStatus>
19 </apex:outputPanel>
20 </apex:page>
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 147
U
AL
N
Many Visualforce
TE
tags relate to
different UI
components.t
IN
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 149
U
AL
N
This method of having the button or link click trigger the refresh is
TE
simple to implement, but often there are better ways to improve the
user experience.
Example: instead of clicking a link, the detail section should refresh
IN
1 <apex:page standardController="Account">
2
3 <!- Same as previous example-->
4
5 <apex:outputPanel>
6 <apex:actionSupport event="onmouseover"
event "onmouseover" rerender="detail">
rerender "detail">
7 <apex:param name="cid" value="{!contact.id}"/>
8 </apex:actionSupport>
9 {!contact.Name}
10 </apex:outputPanel>
11 </apex:column>
12 </apex:dataTable>
13 </apex:form>
14 </apex:pageBlock>
15 <apex:outputPanel id="detail">
16 <apex:actionStatus startText="Requesting...">
LY
17 <apex:facet name="stop">
18 <apex:detail
p subject="{!$CurrentPageReference.parameters.cid}"
j g p
relatedList="false" title="false"/>
19 </apex:facet>
20 </apex:actionStatus>
N
21 </apex:outputPanel>
22 </apex:page>
O
SE
Copyright 2010 salesforce.com, inc. 151
U
AL
N
LY
Tasks:
Add the pre-existing Visualforce page to your org.
N
Override the Position New button.
Test the page.
O
SE
Copyright 2010 salesforce.com, inc. 153
U
AL
N
You can optionally attach the page to a button, make it inline, etc.
For more information on using the AJAX Toolkit to contact the Salesforce
Web Services API, refer to the AJAX Toolkit Developers Guide
documentation.
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 155
U
AL
N
Module 7:
R
Introduction to
TE
Visualforce ((Apex)
p )
IN
Controllers
Visualforce Pages
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
156
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 157
U
AL
N
Module Agenda
R
Controller Overview
TE
Standard Controllers
Custom Controllers
IN
Controller Extensions
LY
Are invoked by using: <apex:page
standardController=Contact>
N
O
SE
Copyright 2010 salesforce.com, inc. 159
U
AL
N
Custom Controllers:
TE
Controller Overview
Standard Controllers
Custom Controllers
Controller Extensions
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 161
U
AL
N
Standard Controllers
R
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 163
U
AL
N
As with API queries, you can use merge field expression syntax to
TE
Example: {!contact.Account.Owner.FirstName}
You can traverse down one level of parent-to-child relationships to
return an array of all child rows for that parent.
Example: {!account.Contacts}
LY
cancel()
N
O
SE
Copyright 2010 salesforce.com, inc. 165
U
AL
N
controller that allows you to create pages that display and act on a set
of records, such as list pages, related lists, and mass action pages.
To select the standard list controller instead of the regular standard
IN
Pages that use standard list controllers can be used in much the same
way as pages with regular controllers.
For example,
p yyou can override standard or create custom buttons,
links, and tabs.
Standard list controllers provide additional pagination actions that
regular controllers do not, such as first, last, next, and
previous.
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 167
U
AL
N
2 <apex:pageBlock >
3 <apex:pageBlockTable value="{!accounts}" var="a">
4 <apex:column value="{!a.name}"/>
5 </ape pageBlockTable>
</apex:pageBlockTable>
6 </apex:pageBlock>
IN
7 </apex:page>
Controller Overview
Standard Controllers
Custom Controllers
Controller Extensions
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 169
U
AL
N
Custom Controllers
R
A custom controller is an Apex class that implements all of the logic for a
TE
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 171
U
AL
N
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 173
U
AL
N
<apex:commandLink>
<apex:actionPoller>
<apex:actionSupport>
<apex:actionFunction>
The action attribute value is written in the form of {!methodName}.
This
Thi methodName mustt map to
t a method
th d on the
th controller.
t ll
Remember: standard controllers come with save(), edit(),
delete(), and cancel() methods.
Action methods may also include navigation controls.
LY
https://salesforceserver.salesforce.com
For a non-Salesforce website:
N
PageReference pageRef = new
PageReference(fullURL);
O
SE
Copyright 2010 salesforce.com, inc. 175
U
AL
N
pageRef.setRedirect(true);
return pageRef;
IN
LY
Tasks:
Add the pre-existing Visualforce page to your org.
Add the Controller class.
N
Test the page by searching for candidates.
O
SE
Copyright 2010 salesforce.com, inc. 177
U
AL
N
Module Agenda
R
Controller Overview
TE
Standard Controllers
Custom Controllers
IN
Controller Extensions
LY
extensions attribute to identify the controller extension.
N
O
SE
Copyright 2010 salesforce.com, inc. 179
U
AL
N
Goal:
20 min. Use a controller extension to help create a dynamic page that changes
TE
location for all candidates on a given position. The company wants a table
that shows the candidates on the vertical axis and the review role
(General, Technical, etc.) on the horizontal access, with review scores
averaged in the table. When a user clicks a cell, it should display the
details of that review below the table. Note that the Recommended for
Hire field counts as a 5 if true and a 1 if false.
Tasks:
Add the style sheet as a static resource.
Add the pre-existing custom controller.
Create the Visualforce page.
Add a custom button on the Position page layout to access the page.
Test the page.
LY
Create the new jjob application
pp page.
p g
N
O
SE
Copyright 2010 salesforce.com, inc. 181
U
AL
N
Module Review
R
Visualforce Pages
LY
N
www.salesforce.com/training
O
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
SE
183
U
AL
N
Module Objectives
R
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 185
U
AL
N
Force.com Sites
R
Create public
TE
names.
Sites are built with All Your Websites All Your Intranets
Visualforce pages
and can include
data and content
from a Salesforce
application
application.
All Your Portals All Your Web Apps
LY
N
Create a Force.com Site Activate!
O
SE
Copyright 2010 salesforce.com, inc. 187
U
AL
N
Consumer reviews
Hotel concierge
g services
IN
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 189
U
AL
N
Salesforce Mobile
R
LY
Reproducing functionality not available declaratively
declaratively.
Integrating with a peripheral device, such as Bluetooth or GPS.
N
Overriding standard button actions.
O
Try to use Apex triggers over Visualforce where possible.
SE
Copyright 2010 salesforce.com, inc. 191
U
AL
N
Designs that work for desktop browser will likely not offer a good
TE
The standard Salesforce style sheets are too massive for the mobile
browser.
Create reusable styles in a separate page and then use the include
component to bring in the styles.
Creating the styles as a static resource pairs it with the client-side
Visualforce markup and increases the page load time.
If working on the iPhone, you can use iUI, a third-party library that
provides an iPhone-like interface.
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 193
U
AL
N
browser.
On the iPhone, this is the same full-feature Safari browser that has
excellent JavaScript support.
IN
LY
Conditional Code
Create pages that evaluate which device is being used and offer
N
appropriate markup for each client.
O
SE
Copyright 2010 salesforce.com, inc. 195
U
AL
N
Mobile devices have a few additional functions that are not applicable
TE
to desktop clients.
You can use the following
g JavaScript
p functions for JavaScript-enabled
p
devices:
IN
After developing the Visualforce pages for mobile clients, you need to
integrate the pages into the mobile application.
Create a new mobile-readyy Visualforce tab.
Your Name | Setup | Create | Tabs | New Visualforce Tab
Check the Mobile Ready checkbox
Choose the profile visibility
If the page is only for mobile clients, remove the new tab from
available apps
LY
Add the Visualforce tab to a mobile configuration
configuration.
Test the page using a mobile client simulator.
N
O
SE
Copyright 2010 salesforce.com, inc. 197
U
AL
N
<messaging:emailTemplate>
R
LY
N
O
SE
Copyright 2010 salesforce.com, inc. 199
U
AL
N
Visualforce
R
TE
Appendix
IN
www.salesforce.com/training
Copyright 2010 salesforce.com, inc.
Various trademarks held by their respective owners.
200
LY
$Resource
$SControl
N
$System.OriginDateTime
$User
O
$UserRole
SE
Copyright 2010 salesforce.com, inc. 201
U
AL
N
Appendix: Functions
R
AND
IF
NOT
OR
BEGINS
CONTAINS
LEN
TRIM
URLFOR
Copyright 2010 salesforce.com, inc. All rights reserved. 100 Visualforce Pages
Appendix: Expression Operators
The following is a list of operations available using the
expression syntax in a Visualforce page:
+ (can also be used for string concatenation)
-
*
/
^
()
=
<>
LY
<
>
<=
N
>=
O
&
SE
Copyright 2010 salesforce.com, inc. 203
U
AL
N
Copyright 2010 salesforce.com, inc. All rights reserved. 101 Visualforce Pages