Visualforce Cheat Sheet
Visualforce Cheat Sheet
Visualforce Cheat Sheet
Overview
The reRender attribute on action tags such as <apex:commandButton> lets you refresh a
part of a page. The following tags provide additional AJAX and JavaScript support:
Getting Started
Enable Developer Mode by clicking Your Name | Setup | My Personal Information |
Personal Information | Edit. Select the Development Mode checkbox to enable an inline
Visualforce editor. To create a page, navigate to a URL based on your current instance, like:
<apex:actionFunction>
<apex:actionPoller>
<apex:actionRegion>
https://<instance>.salesforce.com/apex/helloWorld
<apex:actionStatus>
<apex:actionSupport>
All Visualforce page markup lies within an <apex:page> tag. Heres a simple page:
Core Form
<apex:page showHeader="false">
<h1>Hello World</h1>
</apex:page>
All tags take an optional or required set of attributes, such as showHeader above. Use the
inline editor auto-completion, or the Component Reference, to determine the attributes for
components.
List all Visualforce pages and Apex classes by navigating to Your Name | Setup | Develop.
Example
Visualforce supports auto-generated standard controllers, as well as extensions, to minimize the
amount of coding needed. Heres an example of a Visualforce page that uses a custom controller:
<apex:page showHeader="false" controller="Hello">
<apex:form>
<apex:inputText value="{!theText}"/>
<apex:commandButton value="Go">
action="{!action}" reRender="dynamic"/>
</apex:form>
<apex:outputPanel id="dynamic">
{!theText}
</apex:outputPanel>
</apex:page>
Here are the core components used in forms. These should be embedded within a single
<apex:form> component on a page:
Container for input components.
A form button used to submit or reset a form.
An HTML link that performs an action.
An HTML input element of type checkbox.
Input element that corresponds to a field on a standard or
custom object.
<apex:inputFile>
An input field to upload a file.
<apex:inputHidden>
An HTML input element of type hidden.
<apex:inputSecret>
An HTML input element of type password.
<apex:inputText>
An HTML input element of type text.
<apex:inputTextArea>
An HTML input element of type text area.
<apex:selectList>
A list of options for radio buttons or checkboxes.
<apex:selectRadio>
A set of related radio button input elements, displayed in a table.
<apex:selectOption>
A possible value for the <apex:selectCheckboxes> or
<apex:selectList> components.
<apex:selectCheckboxes> A set of related checkbox input elements, displayed in a table.
<apex:form>
<apex:commandButton>
<apex:commandLink>
<apex:inputCheckbox>
<apex:inputField>
<apex:selectOptions>
This Visualforce page displays an input field and a button labeled Go. When clicked, it
sends the value of the field to the controller, which performs an action on it. Here, it
duplicates the input. The page renders the result using an AJAX update. Heres the controller:
Core Output
<apex:outputField>
<apex:outputLabel>
<apex:outputLink>
A link to a URL.
<apex:outputPanel >
<apex:outputText>
Core Tags
Here are core tags that often make up a Visualforce page:
<apex:page>
Mirroring many of the Core Form Components, these components are used for outputting text:
<apex:includeScript>
<apex:stylesheet>
Template System
Template components let you create Visualforce pages that act as templates, having named
areasinsertsthat must be filled when the template is used.
<apex:dataTable>
An HTML table.
<apex:column>
<apex:dataList>
<apex:facet>
<apex:panelGrid>
<apex:panelGroup>
Miscellaneous HTML
<apex:insert>
These components generate HTML for embedding flash, iframes and images:
<apex:composition>
<apex:flash>
<apex:iframe>
<apex:image>
<apex:define>
http://developer.salesforce.com
Miscellaneous Visualforce
Ideas
<apex:repeat>
<apex:message>
<apex:messages>
<apex:include>
<apex:param>
<apex:scontrol>
<apex:variable>
<ideas:detailOutputLink>
<ideas:listOutputLink>
<ideas:profileListOutputLink>
Knowledge
You can embed Knowledge functionality on your pages:
<knowledge:articleCaseToolbar>
<knowledge:articleList>
<knowledge:articleRendererToolbar>
<knowledge:articleTypeList>
CRUD and other screens have a standard look and feel. The following components
generate output that conforms to that look and feel:
<knowledge:categoryList>
<apex:detail>
<apex:enhancedList>
<apex:pageBlock>
<apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:pageBlockSectionItem>
<apex:listViews>
<apex:relatedList>
<apex:pageBlockTable>
<apex:pageMessage>
Chatter
Add Chatter UI widgets:
<chatter:feed>
<chatter:feedWithFollowers>
<chatter:follow>
<chatter:followers>
Workflow
Components that present your process workflow:
Embeds a Flow interview in the page.
<flow:interview>
Global Variables
These reference general information about the current user and your organization on a
Visualforce page:
<apex:panelBarItem>
<apex:sectionHeader>
<apex:tab>
$ObjectType
<apex:tabPanel>
$Organization
$Page
$Resource
$SControl
$Site
$System.OriginDateTime
$User
<apex:pageMessages>
<apex:panelBar>
<apex:toolbar>
<apex:toolbarGroup>
Custom Components
Create your own components that will reside in the c namespace, for example
<c:helloWorld/>:
$Action
$API
$Component
$CurrentPage
$Label
<apex:component>
<apex:attribute>
$UserRole
$Profile
<apex:componentBody>
Static Resources
Sites
Sites is based on Visualforce pages, and the the following tags provide additional functionality:
Upload static resources, such as stylesheets and images, into a zip, and then reference them
using the URLFOR formula and $Resource merge field. For example, if youve uploaded
images/Blue.jpg into a zip called TestZip, reference it like this:
<site:googleAnalyticsTracking>
<apex:includeScript value="{!$Resource.jquery}"/>
<site:previewAsAdmin>
Apex Support
Messaging
Visualforce can also be used to create email templates:
Here are Apex classes, available in the ApexPages namespace, which can be used to
reference Visualforce functionality:
Action
<messaging:attachment>
Message
<messaging:emailHeader>
PageReference
<messaging:emailTemplate>
SelectOption
<messaging:htmlEmailBody>
<messaging:plainTextEmailBody>
StandardController
StandardSetController
10132014