0% found this document useful (0 votes)
503 views810 pages

Salesforce Pages Developers Guide

Salesforce Pages Developers Guide

Uploaded by

anyname
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
503 views810 pages

Salesforce Pages Developers Guide

Salesforce Pages Developers Guide

Uploaded by

anyname
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 810

Visualforce Developer Guide

Version 47.0, Winter ’20

@salesforcedocs
Last updated: October 31, 2019
© Copyright 2000–2019 salesforce.com, inc. All rights reserved. Salesforce is a registered trademark of salesforce.com, inc.,

as are other names and marks. Other marks appearing herein may be trademarks of their respective owners.
CONTENTS

Chapter 1: Introducing Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


What is Visualforce? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Which Editions Support Visualforce? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Which Permissions are Required for Visualforce Development? . . . . . . . . . . . . . . . . . . . . . . . 4
How is Visualforce Architected? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
What are the Benefits of Visualforce? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
When Should I Use Visualforce? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
How Do Visualforce Pages Compare to S-Controls? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
How is Visualforce Versioned? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
What’s New in Visualforce Version 47.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Documentation Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

Chapter 2: Tools for Visualforce Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12


Using the Development Mode Footer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
About the Visualforce Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Accessing Metrics for Your Visualforce Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Chapter 3: Getting a Quick Start with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17


Compiling Visualforce Successfully . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Creating Your First Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Displaying Field Values with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Using the Visualforce Component Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Overriding an Existing Page with a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Redirecting to a Standard Object List Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Using Input Components in a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Adding and Customizing Input Field Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Setting the Tab Order for Fields in a Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Adding Dependent Fields to a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Creating Visualforce Dashboard Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Displaying Related Lists for Custom Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Enabling Inline Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Converting a Page to a PDF File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Building a Table of Data in a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Editing a Table of Data in a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Using Query String Parameters in a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Getting Query String Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Setting Query String Parameters in Links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Getting and Setting Query String Parameters on a Single Page . . . . . . . . . . . . . . . . . . . 42
Using Ajax in a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Contents

Implementing Partial Page Updates with Command Links and Buttons . . . . . . . . . . . . . 43


Providing Status for Asynchronous Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Applying Ajax Behavior to Events on Any Component . . . . . . . . . . . . . . . . . . . . . . . . . 45
Putting Visualforce Pages on External Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

Chapter 4: Customizing the Appearance and Output of Visualforce Pages . . . . . . . . 47


Styling Visualforce Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Using Salesforce Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Extending Salesforce Styles with Stylesheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Using the Lightning Design System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Style Existing Visualforce Pages with Lightning Experience Stylesheets . . . . . . . . . . . . . . 50
Using Custom Styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Suppressing the Salesforce User Interface and Styles . . . . . . . . . . . . . . . . . . . . . . . . . 56
Defining Styles for a Component’s DOM ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Using Styles from Salesforce Stylesheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Identifying the Salesforce Style Your Users See . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Determining the Salesforce Style That Users See in JavaScript . . . . . . . . . . . . . . . . . . . . 58
HTML Comments and IE Conditional Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
HTML Tags Added or Modified by Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Relaxed Tidying for the HTML5 Doctype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Manually Override Automatic <html> and <body> Tag Generation . . . . . . . . . . . . . . . . 61
Creating an Empty HTML5 “Container” Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Using a Custom Doctype . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Using a Custom ContentType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Setting Custom HTML Attributes on Visualforce Components . . . . . . . . . . . . . . . . . . . . . . . . 64
Offline Caching Using the HTML5 manifest Attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Render a Visualforce Page as a PDF File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Add a Save as PDF Feature to a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Render a Visualforce Page as PDF from Apex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Fonts Available When Using Visualforce PDF Rendering . . . . . . . . . . . . . . . . . . . . . . . 76
Visualforce PDF Rendering Considerations and Limitations . . . . . . . . . . . . . . . . . . . . . 79
Component Behavior When Rendered as PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

Chapter 5: Standard Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83


Associating a Standard Controller with a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . 83
Accessing Data with a Standard Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Using Standard Controller Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Validation Rules and Standard Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Styling Pages that Use Standard Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Checking for Object Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

Chapter 6: Standard List Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88


Associating a Standard List Controller with a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . 88
Accessing Data with List Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Contents

Using Standard List Controller Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91


Pagination with a List Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Using List Views with Standard List Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Editing Records with List Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Chapter 7: Custom Controllers and Controller Extensions . . . . . . . . . . . . . . . . . . . . . 96


What are Custom Controllers and Controller Extensions? . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Building a Custom Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Building a Controller Extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Building a Custom List Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Controller Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Controller Class Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Working with Large Sets of Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Setting Read-Only Mode for an Entire Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
Setting Read-Only Mode for Controller Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Considerations for Creating Custom Controllers and Controller Extensions . . . . . . . . . . . . . . 107
Order of Execution in a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Order of Execution for Visualforce Page Get Requests . . . . . . . . . . . . . . . . . . . . . . . . 109
Order of Execution for Visualforce Page Postback Requests . . . . . . . . . . . . . . . . . . . . . 111
Examples of Visualforce Page Execution Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Testing Custom Controllers and Controller Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Validation Rules and Custom Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Using the transient Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

Chapter 8: Live Controller (Pilot) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126


Quick Start: Get Started with Live Controller in Lightning Experience . . . . . . . . . . . . . . . . . . . 127
Subscribe to a Single Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Subscribe to Multiple Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Reset Data Stored by Custom Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Live Controller Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135

Chapter 9: Advanced Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136


Creating Your First Custom Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Creating a Custom Controller Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Defining Getter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Defining Action Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Defining Navigation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Creating a Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Advanced Visualforce Dashboard Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Integrating Visualforce and Google Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Mass-Updating Records with a Custom List Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . 156

Chapter 10: Overriding Buttons, Links, and Tabs with Visualforce . . . . . . . . . . . . . . . 159
Overriding Tabs Using a Standard List Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Defining Custom Buttons and Links for Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Contents

Adding Custom List Buttons using Standard List Controllers . . . . . . . . . . . . . . . . . . . . . . . . 162


Displaying Record Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164

Chapter 11: Using Static Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165


Creating a Static Resource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Referencing a Static Resource in Visualforce Markup . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Referencing Untrusted Third-Party Content with iframes . . . . . . . . . . . . . . . . . . . . . . . . . . 167

Chapter 12: Creating and Using Custom Components . . . . . . . . . . . . . . . . . . . . . . . 169


What are Custom Components? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Defining Custom Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Custom Component Markup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Using Custom Components in a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Managing Version Settings for Custom Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Custom Component Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Custom Component Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

Chapter 13: Dynamic Visualforce Bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176


Using Dynamic References with Standard Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Using Dynamic References with Custom Objects and Packages . . . . . . . . . . . . . . . . . . . . . 186
Referencing Apex Maps and Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Working with Field Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Dynamic References to Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Dynamic References to Static Resources Using $Resource . . . . . . . . . . . . . . . . . . . . . 195
Dynamic References to Action Methods Using $Action . . . . . . . . . . . . . . . . . . . . . . . . 197
Dynamic References to Schema Details Using $ObjectType . . . . . . . . . . . . . . . . . . . . 199

Chapter 14: Dynamic Visualforce Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203


Dynamic Components Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Creating and Displaying Dynamic Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Deferred Creation of Dynamic Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Example Using a Related List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

Chapter 15: Integrating Email with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215


Sending an Email with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Creating a Custom Controller with the Messaging Class . . . . . . . . . . . . . . . . . . . . . . 215
Creating an Email Attachment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Visualforce Email Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Creating a Visualforce Email Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Using a Custom Stylesheet in a Visualforce Email Template . . . . . . . . . . . . . . . . . . . . 225
Adding Attachments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Using Custom Controllers within Visualforce Email Templates . . . . . . . . . . . . . . . . . . 232

Chapter 16: Visualforce Charting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234


Visualforce Charting Limitations and Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Contents

How Visualforce Charting Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235


A Simple Charting Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Providing Chart Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Building a Complex Chart with Visualforce Charting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Updating Charts with Refreshed Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Refreshing Chart Data Using <apex:actionSupport> . . . . . . . . . . . . . . . . . . . . . . . . . 245
Refreshing Chart Data Using JavaScript Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . 247
Controlling the Appearance of Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Chart Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Chart Layout and Annotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Bar Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Other Linear Series Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Pie Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Gauge Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259
Radar Charts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

Chapter 17: Creating Maps with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262


Creating Basic Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Adding Location Markers to a Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Using Custom Marker Icons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Adding Info Windows to Markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Example of Building Map Data in Apex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

Chapter 18: Render Flows with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274


Embed Flows in Visualforce Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
An Advanced Example of Using <flow:interview> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Set Flow Variable Values from a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Get Flow Variable Values to a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
Control Whether Users Can Pause a Flow from a Visualforce Page . . . . . . . . . . . . . . . . . . 284
Customize How Users Resume Paused Flow Interviews . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Configure the finishLocation Attribute in a Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Customize a Flow’s User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Render Lightning Flow Runtime in a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289

Chapter 19: Templating with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291


Defining Templates with <apex:composition> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
Referencing an Existing Page with <apex:include> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295

Chapter 20: Developing Salesforce Apps with Visualforce . . . . . . . . . . . . . . . . . . . . 297


Salesforce Platform Development Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
Setting Up Your Development System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
The Development Process and the Importance of Testing . . . . . . . . . . . . . . . . . . . . . 298
Testing Visualforce Pages in the Salesforce App . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Understanding the Salesforce App Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Tell Me More: Where Visualforce Pages Can Appear in the Salesforce Mobile App . . . . . . . . 300
Contents

Guidelines and Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302


Sharing Visualforce Pages Between Mobile and Desktop . . . . . . . . . . . . . . . . . . . . . 303
Excluding Visualforce Pages from Mobile or Desktop . . . . . . . . . . . . . . . . . . . . . . . . 304
Creating Visualforce Pages That Work in Mobile and Desktop . . . . . . . . . . . . . . . . . . 304
Choosing an Architecture for Visualforce Pages in the Salesforce App . . . . . . . . . . . . . 305
Optimizing the Performance of Visualforce Pages in the Salesforce App . . . . . . . . . . . . 313
Visualforce Components and Features to Avoid in the Salesforce App . . . . . . . . . . . . . 313
Known Visualforce Mobile Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Considerations and Limitations for Using Visualforce in the Salesforce App . . . . . . . . . . 319
Prepare a Support Request for Problems with Visualforce Pages in the Salesforce App . . 320
Choosing an Effective Page Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
User Input and Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Managing Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
Introduction to the Salesforce Lightning Design System . . . . . . . . . . . . . . . . . . . . . . . 333
Using Visualforce Pages as Custom Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Performance Tuning for Visualforce Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341

Chapter 21: Adding Visualforce to a Salesforce AppExchange App . . . . . . . . . . . . . 343


Managing Package Version Settings for Visualforce Pages and Components . . . . . . . . . . . 344

Chapter 22: Using JavaScript in Visualforce Pages . . . . . . . . . . . . . . . . . . . . . . . . . 345


Using $Component to Reference Components from JavaScript . . . . . . . . . . . . . . . . . . . . . 345
Using JavaScript Libraries with Visualforce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
JavaScript Remoting for Apex Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
What Is JavaScript Remoting? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
When to Use JavaScript Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Adding JavaScript Remoting to a Visualforce Page . . . . . . . . . . . . . . . . . . . . . . . . . . 349
Declaring a Remote Method in Apex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
Handling the Remote Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Debugging JavaScript Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
JavaScript Remoting Limits and Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
JavaScript Remoting Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Visualforce Remote Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
A Simple Example of Remote Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359
Using Remote Objects in JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
An Example of Using Remote Objects with jQuery Mobile . . . . . . . . . . . . . . . . . . . . . 378
Best Practices for Using Remote Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Remote Objects Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384

Chapter 23: Communicating Across the DOM with Lightning Message Service
(Developer Preview) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385
Create a Message Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Publish on a Message Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Subscribe and Unsubscribe from a Message Channel . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Contents

Considerations and Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389

Chapter 24: Best Practices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390


Best Practices for Improving Visualforce Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
Best Practices for Accessing Component IDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Best Practices for Static Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Best Practices for Controllers and Controller Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . 395
Best Practices for Using Component Facets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396
Best Practices for Page Block Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Best Practices for Rendering PDF Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Best Practices for <apex:panelbar> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399

Chapter 25: Standard Component Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400


analytics:reportChart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400
apex:actionFunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402
apex:actionPoller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
apex:actionRegion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
apex:actionStatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
apex:actionSupport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
apex:areaSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
apex:attribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
apex:axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
apex:barSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
apex:canvasApp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
apex:chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
apex:chartLabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
apex:chartTips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
apex:column . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
apex:commandButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
apex:commandLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439
apex:component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443
apex:componentBody . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
apex:composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
apex:dataList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
apex:dataTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
apex:define . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 457
apex:detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 458
apex:dynamicComponent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
apex:emailPublisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
apex:enhancedList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
apex:facet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465
apex:flash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
apex:form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
apex:gaugeSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Contents

apex:iframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
apex:image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474
apex:include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
apex:includeLightning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
apex:includeScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
apex:inlineEditSupport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479
apex:input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
apex:inputCheckbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
apex:inputField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
apex:inputFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
apex:inputHidden . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
apex:inputSecret . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
apex:inputText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
apex:inputTextarea . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
apex:insert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
apex:legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
apex:lineSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
apex:listViews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
apex:liveController (Pilot) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 510
apex:logCallPublisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
apex:map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
apex:mapInfoWindow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
apex:mapMarker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
apex:message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 518
apex:messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
apex:milestoneTracker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
apex:outputField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523
apex:outputLabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524
apex:outputLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
apex:outputPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
apex:outputText . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
apex:page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
apex:pageBlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
apex:pageBlockButtons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
apex:pageBlockSection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544
apex:pageBlockSectionItem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
apex:pageBlockTable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
apex:pageMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
apex:pageMessages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
apex:panelBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559
apex:panelBarItem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
apex:panelGrid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
apex:panelGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
apex:param . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
Contents

apex:pieSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
apex:radarSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 571
apex:relatedList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
apex:remoteObjectField . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
apex:remoteObjectModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
apex:remoteObjects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
apex:repeat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
apex:scatterSeries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
apex:scontrol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
apex:sectionHeader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
apex:selectCheckboxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
apex:selectList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
apex:selectOption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
apex:selectOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
apex:selectRadio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 596
apex:slds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
apex:stylesheet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 602
apex:tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603
apex:tabPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
apex:toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
apex:toolbarGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613
apex:variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
apex:vote . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
chatter:feed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
chatter:feedWithFollowers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
chatter:follow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618
chatter:followers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
chatter:newsfeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
chatter:userPhotoUpload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
chatteranswers:aboutme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 620
chatteranswers:allfeeds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621
chatteranswers:changepassword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
chatteranswers:datacategoryfilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
chatteranswers:feedfilter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
chatteranswers:feeds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
chatteranswers:forgotpassword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624
chatteranswers:forgotpasswordconfirm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
chatteranswers:guestsignin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
chatteranswers:help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
chatteranswers:login . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626
chatteranswers:registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627
chatteranswers:searchask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
chatteranswers:singleitemfeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 628
flow:interview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629
Contents

ideas:detailOutputLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 630
ideas:listOutputLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
ideas:profileListOutputLink . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
knowledge:articleCaseToolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
knowledge:articleList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
knowledge:articleRendererToolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
knowledge:articleTypeList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
knowledge:categoryList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 638
liveAgent:clientChat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
liveAgent:clientChatAlertMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639
liveAgent:clientChatCancelButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
liveAgent:clientChatEndButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
liveAgent:clientChatFileTransfer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 642
liveAgent:clientChatInput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
liveAgent:clientChatLog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
liveAgent:clientChatLogAlertMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
liveAgent:clientChatMessages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
liveAgent:clientChatQueuePosition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
liveAgent:clientChatSaveButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646
liveAgent:clientChatSendButton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
liveAgent:clientChatStatusMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
messaging:attachment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648
messaging:emailHeader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
messaging:emailTemplate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
messaging:htmlEmailBody . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
messaging:plainTextEmailBody . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
site:googleAnalyticsTracking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656
site:previewAsAdmin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657
social:profileViewer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
support:caseArticles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
support:caseFeed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
support:caseUnifiedFiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 661
support:clickToDial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
support:portalPublisher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
topics:widget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
wave:dashboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665

APPENDICES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669

Appendix A: Global Variables, Functions, and Expression Operators . . . 669


Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
$Action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671
$Api . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
$Asset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
Contents

$Cache.Org . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
$Cache.Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
$Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682
$ComponentLabel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
$CurrentPage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
$FieldSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684
$Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684
$Label.Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 684
$MessageChannel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
$Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
$ObjectType . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
$Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
$Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694
$Permission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694
$Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 694
$Resource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
$SControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
$Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696
$Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697
$System.OriginDateTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 699
$User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
$User.UITheme and $User.UIThemeDisplayed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700
$UserRole . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701
Expression Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714

Appendix B: Security Tips for Apex and Visualforce Development . . . . . . 717


Cross Site Scripting (XSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717
Unescaped Output and Formulas in Visualforce Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Cross-Site Request Forgery (CSRF) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720
SOQL Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
Data Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723

Appendix C: Apex Classes Used in Visualforce Controllers . . . . . . . . . . . 724


ApexPages Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
ApexPages Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725
Action Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
Action Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Action Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
Cookie Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
Cookie Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
Cookie Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
IdeaStandardController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734
IdeaStandardController Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
Contents

IdeaStandardSetController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736


IdeaStandardSetController Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739
KnowledgeArticleVersionStandardController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740
KnowledgeArticleVersionStandardController Constructors . . . . . . . . . . . . . . . . . . . . . 742
KnowledgeArticleVersionStandardController Methods . . . . . . . . . . . . . . . . . . . . . . . 742
Message Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743
Message Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 744
Message Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 746
PageReference Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 747
PageReference Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 750
PageReference Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751
SelectOption Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 757
SelectOption Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 758
SelectOption Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759
StandardController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
StandardController Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
StandardController Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 764
StandardSetController Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 768
StandardSetController Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
StandardSetController Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770

Appendix D: Execution Governors and Limits . . . . . . . . . . . . . . . . . . . . . . . 778

GLOSSARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 786

INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795
CHAPTER 1 Introducing Visualforce
Over the past several years, Salesforce has created a comprehensive platform for building on-demand applications. Like other sophisticated
application development platforms, the Lightning platform offers separate tools for defining:
• The structure of the data—that is, the data model
• The rules that detail how that data can be manipulated—that is, the business logic
• The layouts that specify how that data should be displayed—that is, the user interface

Note: Splitting up application development tools based on whether they affect the data model, business logic, or user interface
is also known as the Model-View-Controller (MVC) application development pattern—the Model is the data model, the View is
the user interface, and the Controller is the business logic.
While the tools for building the data model and business logic for applications are powerful solutions that run natively on Lightning
platform servers, the existing tools for defining user interfaces have had certain limitations:
• Page layouts, the point-and-click tool that allows application developers to organize fields, buttons, and related lists on record
detail pages, do not provide much flexibility in how sets of information are displayed. Fields must always appear above related lists,
buttons must always appear above fields, and s-controls and custom links can only be placed in particular areas.
• S-controls, the tool that allows application developers to display custom HTML in a detail page or custom tab, provide more flexibility
than page layouts, but:
– Execute from within a browser, causing poor performance if displaying or updating values from more than a few records at a
time
– Do not provide an easy way to give custom user interface elements the same look-and-feel as standard Salesforce pages
– Require developers to enforce field uniqueness and other metadata dependencies on their own

Important: Visualforce pages supersede s-controls. Organizations that haven’t previously used s-controls can’t create them.
Existing s-controls are unaffected, and can still be edited.

For these reasons, Salesforce has introduced Visualforce, the next-generation solution for building sophisticated custom user interfaces
on the Lightning platform.

SEE ALSO:
How is Visualforce Architected?
What are the Benefits of Visualforce?
Which Editions Support Visualforce?
How Do Visualforce Pages Compare to S-Controls?
What is Visualforce?
What’s New in Visualforce Version 47.0

1
Introducing Visualforce What is Visualforce?

What is Visualforce?
Visualforce is a framework that allows developers to build sophisticated, custom user interfaces that can be hosted natively on the
Lightning platform. The Visualforce framework includes a tag-based markup language, similar to HTML, and a set of server-side “standard
controllers” that make basic database operations, such as queries and saves, very simple to perform.
In the Visualforce markup language, each Visualforce tag corresponds to a coarse or fine-grained user interface component, such as a
section of a page, a related list, or a field. The behavior of Visualforce components can either be controlled by the same logic that is used
in standard Salesforce pages, or developers can associate their own logic with a controller class written in Apex.

Sample of Visualforce Components and their Corresponding Tags

What is a Visualforce Page?


Developers can use Visualforce to create a Visualforce page definition. A page definition consists of two primary elements:
• Visualforce markup
• A Visualforce controller

Visualforce Markup
Visualforce markup consists of Visualforce tags, HTML, JavaScript, or any other Web-enabled code embedded within a single
<apex:page> tag. The markup defines the user interface components that should be included on the page, and the way they should
appear.

Visualforce Controllers
A Visualforce controller is a set of instructions that specify what happens when a user interacts with the components specified in associated
Visualforce markup, such as when a user clicks a button or link. Controllers also provide access to the data that should be displayed in a
page, and can modify component behavior.
A developer can either use a standard controller provided by the Lightning platform, or add custom controller logic with a class written
in Apex:
• A standard controller consists of the same functionality and logic that is used for a standard Salesforce page. For example, if you use
the standard Accounts controller, clicking a Save button in a Visualforce page results in the same behavior as clicking Save on a
standard Account edit page.

2
Introducing Visualforce Which Editions Support Visualforce?

If you use a standard controller on a page and the user doesn't have access to the object, the page will display an insufficient privileges
error message. You can avoid this by checking the user's accessibility for an object and displaying components appropriately.

• A standard list controller enables you to create Visualforce pages that can display or act on a set of records. Examples of existing
Salesforce pages that work with a set of records include list pages, related lists, and mass action pages.
• A custom controller is a class written in Apex that implements all of a page's logic, without leveraging a standard controller. If you
use a custom controller, you can define new navigation elements or behaviors, but you must also reimplement any functionality
that was already provided in a standard controller.
Like other Apex classes, custom controllers execute entirely in system mode, in which the object and field-level permissions of the
current user are ignored. You can specify whether a user can execute methods in a custom controller based on the user's profile.

• A controller extension is a class written in Apex that adds to or overrides behavior in a standard or custom controller. Extensions
allow you to leverage the functionality of another controller while adding your own custom logic.
Because standard controllers execute in user mode, in which the permissions, field-level security, and sharing rules of the current
user are enforced, extending a standard controller allows you to build a Visualforce page that respects user permissions. Although
the extension class executes in system mode, the standard controller executes in user mode. As with custom controllers, you can
specify whether a user can execute methods in a controller extension based on the user's profile.

Note: Although custom controllers and controller extension classes execute in system mode and thereby ignore user permissions
and field-level security, you can choose whether they respect a user's organization-wide defaults, role hierarchy, and sharing rules
by using the with sharing keywords in the class definition. For information, see “Using the with sharing, without
sharing, and inherited sharing Keywords” in the Apex Developer Guide.

Where Can Visualforce Pages Be Used?


Developers can use Visualforce pages to:
• Override standard buttons, such as the New button for accounts, or the Edit button for contacts
• Override tab overview pages, such as the Accounts tab home page
• Define custom tabs
• Embed components in detail page layouts
• Create dashboard components or custom help pages
• Customize, extend, or integrate the sidebars in the Salesforce console (custom console components)
• Add navigation menu items and actions in the Salesforce mobile app

SEE ALSO:
Building a Custom Controller
Building a Controller Extension

Which Editions Support Visualforce?


Visualforce is available in Contact Manager, Group, Professional, Enterprise, Unlimited, Performance, and Developer Editions.

3
Introducing Visualforce Which Permissions are Required for Visualforce Development?

Which Permissions are Required for Visualforce Development?


Visualforce development requires various permissions, depending on the specific activity.

User Permissions Needed


To enable Visualforce development mode: “Customize Application”

To create, edit, or delete Visualforce pages: “Customize Application”

To create and edit custom Visualforce components: “Customize Application”

To edit custom Visualforce controllers or Apex “Author Apex”

To set Visualforce page security: “Manage Profiles and Permission Sets”

To set version settings for Visualforce pages: “Customize Application”

To create, edit, or delete static resources: “Customize Application”

To create Visualforce Tabs: “Customize Application”

How is Visualforce Architected?


All Visualforce pages run entirely on the Lightning platform, both when a developer creates the page, and when an end user requests
a page, as shown in the following architecture diagrams.

Visualforce System Architecture - Development Mode

4
Introducing Visualforce What are the Benefits of Visualforce?

When a developer finishes writing a Visualforce page and saves it to the platform, the platform application server attempts to compile
the markup into an abstract set of instructions that can be understood by the Visualforce renderer. If compilation generates errors, the
save is aborted and the errors are returned to the developer. Otherwise, the instructions are saved to the metadata repository and sent
to the Visualforce renderer. The renderer turns the instructions into HTML and then refreshes the developer's view, thereby providing
instantaneous feedback to the developer for whatever changes were made in the markup.
The architecture diagram below shows the process flow when a non-developer user requests a Visualforce page. Because the page is
already compiled into instructions, the application server simply retrieves the page from the metadata repository and sends it to the
Visualforce renderer for conversion into HTML.

Visualforce System Architecture - Standard User Mode

Note: Your Visualforce pages may be run on one of the force.com servers instead of a salesforce.com server.

SEE ALSO:
What is Visualforce?
What are the Benefits of Visualforce?
How Do Visualforce Pages Compare to S-Controls?

What are the Benefits of Visualforce?


As a markup language, Visualforce provides the following benefits:
User-friendly development
Developers can edit their Visualforce markup in the same window that displays the resulting page. Consequently, developers can
instantly verify the result of an edit just by saving their code. The Visualforce editor pane also includes auto-completion and syntax
highlighting.

5
Introducing Visualforce When Should I Use Visualforce?

Visualforce also supports “quick fixes” that allow developers to create supporting components on the fly. For example, a developer
can define a new Visualforce page simply by logging in to Salesforce and then entering the name of the new page in a URL. Much
like a wiki, if the page does not yet exist, the platform creates it for you.
Integration with other Web-based user interface technologies
Because Visualforce markup is ultimately rendered into HTML, designers can use Visualforce tags alongside standard HTML, JavaScript,
Flash, or any other code that can execute within an HTML page on the platform, including Lightning platform merge fields and
expressions.
Model-View-Controller (MVC) style development
Visualforce conforms to the Model-View-Controller (MVC) development pattern by providing a clear division between the view of
an application (the user interface, defined by Visualforce markup), and the controller that determines how the application works (the
business logic, defined by a Visualforce controller written in Apex). With this architecture, designers and developers can easily split
up the work that goes with building a new application—designers can focus on the look and feel of the user interface, while
developers can work on the business logic that drives the app.
Concise syntax
Visualforce pages can implement the same functionality as s-controls but with approximately 90% fewer lines of code.
Data-driven defaults
Visualforce components are rendered intelligently by the platform. For example, rather than forcing page designers to use different
component tags for different types of editable fields (such as email addresses or calendar dates), designers can simply use a generic
<apex:inputField> tag for all fields. The Visualforce renderer displays the appropriate edit interface for each field.
Hosted platform
Visualforce pages are compiled and rendered entirely by the Lightning platform. Because they are so tightly integrated, they display
the same performance as standard Salesforce pages, regardless of the amount of data being displayed or edited.
Automatically upgradeable
Visualforce pages do not need to be rewritten when other parts of the Lightning platform are upgraded. Because the pages are
stored as metadata, they are automatically upgraded with the rest of the system.

When Should I Use Visualforce?


The Salesforce prebuilt applications provide powerful CRM functionality. In addition, Salesforce provides the ability to customize the
prebuilt applications to fit your organization. However, your organization may have complex business processes that are unsupported
by the existing functionality. In this case, Lightning Platform provides various ways for advanced administrators and developers to build
custom functionality. These include Visualforce, Apex, and the SOAP API.

Visualforce
Visualforce consists of a tag-based markup language that gives developers a more powerful way of building applications and customizing
the Salesforce user interface. With Visualforce you can:
• Build wizards and other multistep processes.
• Create your own custom flow control through an application.
• Define navigation patterns and data-specific rules for optimal, efficient application interaction.

Apex
Use Apex if you want to:

6
Introducing Visualforce How Do Visualforce Pages Compare to S-Controls?

• Create Web services.


• Create email services.
• Perform complex validation over multiple objects.
• Create complex business processes that are not supported by workflow.
• Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object).
• Attach custom logic to another operation, such as saving a record, so that it occurs whenever the operation is executed, regardless
of whether it originates in the user interface, a Visualforce page, or from SOAP API.
For more information, see the Apex Developer Guide.

SOAP API
Use standard SOAP API calls if you want to add functionality to a composite application that processes only one type of record at a time
and does not require any transactional control (such as setting a Savepoint or rolling back changes).
For more information, see the SOAP API Developer Guide.

How Do Visualforce Pages Compare to S-Controls?


Important: Visualforce pages supersede s-controls. Organizations that haven’t previously used s-controls can’t create them.
Existing s-controls are unaffected, and can still be edited.
Visualforce pages are considered the next-generation of s-controls and should be used instead of s-controls whenever possible, both
for their increased performance and the ease with which they can be written. The following table outlines the differences between
Visualforce pages and s-controls.

Visualforce Pages S-Controls


Required technical skills HTML, XML HTML, JavaScript, Ajax Toolkit

Language style Tag markup Procedural code

Page override model Assemble standard and custom Write HTML and JavaScript for entire page
components using tags

Standard Salesforce component library Yes No

Access to built-in platform behavior Yes, through the standard controller No

Data binding Yes No


Developers can bind an input component Developers can't bind an input component
(such as a text box) with a particular field with a particular field. Instead, they must
(such as Account Name). If a user saves a write JavaScript code that uses the API to
value in that input component, it is also update the database with user-specified
saved in the database. field values.

Stylesheet inheritance Yes No, must bring in Salesforce stylesheets


manually

7
Introducing Visualforce How is Visualforce Versioned?

Visualforce Pages S-Controls


Respect for field metadata, such as Yes, by default Yes, if coded in JavaScript using a
uniqueness If a user attempts to save a record that describe API call
violates uniqueness or requiredness field If a user attempts to save a record that
attributes, an error message is automatically violates uniqueness or requiredness field
displayed and the user can try again. attributes, an error message is only
displayed if the s-control developer wrote
code that checked those attributes.

Interaction with Apex Direct, by binding to a custom controller Indirect, by using Apex webService
methods through the API

Performance More responsive because markup is Less responsive because every call to the
generated on the Lightning Platform API requires a round trip to the server—the
burden rests with the developer to tune
performance

Page container Native In an iFrame

SEE ALSO:
What is Visualforce?
What are the Benefits of Visualforce?
How is Visualforce Architected?

How is Visualforce Versioned?


Starting with the Summer '09 release, Visualforce pages and components are versioned. When a page or component has a version
number, the functionality of older Visualforce elements does not change as new implementations are introduced. Visualforce versions
start at 15.0. If you try to set the version of a Visualforce page to a version earlier than 15.0, it will automatically be changed to 15.0.
To aid backwards-compatibility, each Visualforce page and custom component is saved with version settings for the specified version
of the API as well as the specific version of Visualforce. If the Visualforce page or component references installed managed packages,
the version settings for each managed package referenced by the page or component is saved too. This ensures that as Visualforce, the
API, and the components in managed packages evolve in subsequent versions, Visualforce pages and components are still bound to
versions with specific, known behavior.
Custom components that are referenced in Visualforce pages always perform under their own version number. Thus, if a custom
component is set at version 15.0, it always exhibits behavior from Visualforce version 15.0, whether running in a version 15.0 or a 16.0
page.
The release notes list any changes between Visualforce versions. The component reference also lists which Visualforce version a standard
component was introduced in, as well as whether a component or attribute was deprecated in a version.
To set the Salesforce API and Visualforce version for a Visualforce page or custom component:
1. Edit a Visualforce page or component and click Version Settings.

Note: You can only modify the version settings for a page or custom component on the Version Settings tab when editing
the page or component in Setup.

8
Introducing Visualforce What’s New in Visualforce Version 47.0

2. Select the Version of the Salesforce API. This is also the version of Visualforce used with the page or component.
3. Click Save.

SEE ALSO:
Managing Version Settings for Custom Components
Managing Package Version Settings for Visualforce Pages and Components

What’s New in Visualforce Version 47.0


Review the current release notes for a summary of new and changed Visualforce features in the latest release.

Past Releases
Our archive of release notes includes details about features we introduced in previous releases.
• Summer ’19 Release Notes
• Spring ’19 Release Notes
• Winter ’19 Release Notes
• Summer ’18 Release Notes
• Spring ’18 Release Notes
• Winter ’18 Release Notes
• Summer ’17 Release Notes
• Spring ’17 Release Notes
• Winter ’17 Release Notes
• Summer ’16 Release Notes
• Spring ’16 Release Notes
• Winter ’16 Release Notes
• Summer ’15 Release Notes
• Spring ’15 Release Notes
• Winter ’15 Release Notes
• Summer ’14 Release Notes
• Spring ’14 Release Notes
• Winter ’14 Release Notes
• Summer ’13 Release Notes
• Spring ’13 Release Notes
• Winter ’13 Release Notes
• Summer ’12 Release Notes
• Spring ’12 Release Notes
• Winter ’12 Release Notes
• Summer ’11 Release Notes
• Spring ’11 Release Notes

9
Introducing Visualforce Documentation Typographical Conventions

• Winter ’11 Release Notes


• Summer ’10 Release Notes
• Spring ’10 Release Notes
• Winter ’10 Release Notes
• Summer ’09 Release Notes
• Spring ’09 Release Notes
• Winter ’09 Release Notes
• Summer ’08 Release Notes
• Spring ’08 Release Notes
• Winter ’08 Release Notes
• Summer ’07 Release Notes
• Spring ’07 Release Notes
• Lightning Platform Mobile 7.0 for BlackBerry Release Notes
• Lightning Platform Mobile 6.1 for Windows Mobile 5 Release Notes
• Winter ’07 Release Notes
• Summer ’06 Release Notes
• Winter ’06 Release Notes
• Lightning Platform Mobile 6.0 Release Notes
• Summer ’05 Release Notes
• Winter ’05 Release Notes
• Summer ’04 Release Notes
• Spring ’04 Release Notes
• Winter ’04 Release Notes

Documentation Typographical Conventions


Apex and Visualforce documentation uses the following typographical conventions.

Convention Description
Courier font In descriptions of syntax, monospace font indicates items that you should type as shown,
except for brackets. For example:
Public class HelloWorld

Italics In descriptions of syntax, italics represent variables. You supply the actual value. In the following
example, three values need to be supplied: datatype variable_name [ = value];
If the syntax is bold and italic, the text represents a code element that needs a value supplied
by you, such as a class name or variable value:

public static class YourClassHere { ... }

Bold Courier font In code samples and syntax descriptions, bold courier font emphasizes a portion of the code
or syntax.

10
Introducing Visualforce Documentation Typographical Conventions

Convention Description
<> In descriptions of syntax, less-than and greater-than symbols (< >) are typed exactly as shown.
<apex:pageBlockTable value="{!account.Contacts}" var="contact">

<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.MailingCity}"/>
<apex:column value="{!contact.Phone}"/>
</apex:pageBlockTable>

{} In descriptions of syntax, braces ({ }) are typed exactly as shown.


<apex:page>
Hello {!$User.FirstName}!
</apex:page>

[] In descriptions of syntax, anything included in brackets is optional. In the following example,


specifying value is optional:

data_type variable_name [ = value];

| In descriptions of syntax, the pipe sign means “or”. You can do one of the following (not all).
In the following example, you can create a new unpopulated set in one of two ways, or you
can populate the set:

Set<data_type> set_name
[= new Set<data_type>();] |
[= new Set<data_type{value [, value2. . .] };] |
;

11
CHAPTER 2 Tools for Visualforce Development
Before you begin developing Visualforce pages and components, familiarize yourself with the different places to create them:
• The best way to build Visualforce development mode is only available for users with the “Customize Application” permission.
Development mode provides you with:
– A special development footer on every Visualforce page that includes the page’s view state, any associated controller, a link to
the component reference documentation, and a page markup editor that offers highlighting, find-replace functionality, and
auto-suggest for component tag and attribute names.
– The ability to define new Visualforce pages just by entering a unique URL.
– Error messages that include more detailed stack traces than what standard users receive.
To enable Visualforce development mode:
1. From your personal settings, enter Advanced User Details in the Quick Find box, then select Advanced User Details.
No results? Enter Personal Information in the Quick Find box, then select Personal Information.
2. Click Edit.
3. Select the Development Mode checkbox.
4. Optionally, select the Show View State in Development Mode checkbox to enable the View State tab on the
development footer. This tab is useful for monitoring the performance of your Visualforce pages.
5. Click Save.

• You can also develop Visualforce pages through the Salesforce user interface from Setup by entering Visualforce Pages in
the Quick Find box, then selecting Visualforce Pages. For Visualforce components, from Setup, enter Components in the
Quick Find box, then select Visualforce Components.
• The Salesforce Extensions for Visual Studio Code, which includes tools for developing on the Salesforce platform in the lightweight,
extensible VS Code editor, providing features for working with development orgs (scratch orgs, sandboxes, and DE orgs), Apex, Aura
components, and Visualforce.

Using the Development Mode Footer


With development mode enabled, you can view and edit the content of a page by navigating to the URL of the page. For example, if a
page is named HelloWorld, and your Salesforce instance is na3.salesforce.com, enter
https://na3.salesforce.com/apex/HelloWorld in your browser's address bar. Development mode also provides you
with a special development footer to edit your Visualforce pages and custom controllers, as well as monitor Visualforce performance.
After enabling development mode, all Visualforce pages display with the development mode footer at the bottom of the browser:
• Click the tab with the name of the page to open the page editor to view and edit the associated Visualforce markup without having
to return to the Setup area. Changes display immediately after you save the page.
• If the page uses a custom controller, the name of the controller class is available as a tab. Click the tab to edit the associated Apex
class.

12
Tools for Visualforce Development Using the Development Mode Footer

• If the page uses any controller extensions, the names of each extension are available as tabs. Clicking on the tab lets you edit the
associated Apex class.
• If enabled in Setup, the View State tab displays information about the items contributing to the view state of the Visualforce page.
• Click Save (just above the edit pane) to save your changes and refresh the content of the page.
• Click Component Reference to view the documentation for all supported Visualforce components.
• Click Where is this used? to view a list of all items in Salesforce that reference the page, such as custom tabs, controllers, or other
pages.
• Click the Collapse button ( ) to collapse the development mode footer p