Unit V Visualforce Development
Unit V Visualforce Development
https://trailhead.salesforce.com/content/learn
/modules/visualforce_fundamentals
Introduction to Visualforce
• Visualforce
• is a web development framework that enables developers to build
sophisticated, custom user interfaces for mobile and desktop apps that can be
hosted on the Lightning Platform.
• use Visualforce to build apps that align with the styling of Lightning
Experience, as well as your own completely custom interface
• enables developers to extend Salesforce’s built-in features, replace them with
new functionality, and build completely new apps.
• Use powerful built-in standard controller features, or write your own custom
business logic in Apex.
• You can build functionality for your own organization, or create apps for sale
in the AppExchange.
Introduction to Visualforce cntd….
• Developers create Visualforce pages by composing components,
HTML, and optional styling elements.
• Visualforce can integrate with any standard web technology or
JavaScript framework to allow for a more animated and rich user
interface.
An Example Visualforce Page
apex:page standardController="Contact" >
<apex:form >
<apex:pageBlockButtons >
<apex:pageBlock title="Edit Contact"> <apex:commandButton action="{!save}"
<apex:pageBlockSection columns="1"> value="Save"/>
<apex:inputField value="{!Contact.FirstName}"/> </apex:pageBlockButtons>
</apex:pageBlock>
<apex:inputField value="{!Contact.LastName}"/>
<apex:inputField value="{!Contact.Email}"/> </apex:form>
<apex:inputField value="{!Contact.Birthdate}"/> </apex:page>
</apex:pageBlockSection>
Creating Visualforce Pages
• Visualforce uses a tag-based markup language that’s similar to HTML.
• Each Visualforce tag corresponds to a coarse or fine-grained user
interface component, such as a section of a page, a list view, or an
individual field.
• Visualforce boasts nearly 150 built-in components, and provides a
way for developers to create their own components.
• Visualforce markup can be freely mixed with HTML markup, CSS
styles, and JavaScript libraries, giving you considerable flexibility in
how you implement your app’s user interface.
Create Visualforce Pages in the Developer Console
• Open the Developer Console under Your Name or the quick access
menu (Setup gear icon).
• The Developer Console opens in a new window.
• Click File | New | Visualforce Page.
• Enter HelloWorld for the name of the new page, and click OK.
• A new, blank Visualforce page opens in the Developer Console.
• In the editor, enter the following markup for the page.
<apex:page>
• Click File | Save. <h1>Hello World</h1>
• To see your new page, click Preview. </apex:page>
Ex:
<apex:page >
<apex:page > <h1>Hello World</h1>
<p>
<h1>Hello World</h1> This is my first visual Page!....
</apex:page> </p>
</apex:page>
Add Attributes Using Auto-Suggest
</apex:page>
Important Visualforce Tags
• <apex:page> • <apex:inputHidden>
• <apex:form> • <apex:inputsecret>
• <apex:pageblock> • <apex:inputText>
• <apex:pageBlockSection> • <apex:inputTextarea>
• <apex:commandButton> • <apex:inputCheckbox>
• <apex:pageBlockButtons> • <apex:outputField>
• <apex:commandLink> • <apex:outputLabel>
• <apex:outputLink> • <apex:outputText>
• <apex:inputField> • <apex:pageBlockSectionItem>
• <apex:inputFile> • <apex:pageBlockTable>
Important Visualforce Tags
• <apex:column> • <apex:actionFunction>
• <apex:dataTable> • <apex:detail>
• <apex:tabPanel> • <apex:actionPoller>
• <apex:tab> • <apex:actionRegion>
• <apex:toolbar> • Message Class
• <apex:toolbarGroup> • <apex:variable>
• <apex:stylesheet>
• <apex:pageMessage>
• Referencing a Static Resource in Visualforce
• <apex:panelBar> Pages
• <apex:panelBarItem> • <apex:SectionHeader >
• <apex:panelGrid> • <apex:relatedList>
• <apex:panelGroup> • <apex:listViews>
• <apex:param> • <apex:enhancedList>
• <apex:repeat> • <apex:actionStatus>
• <apex:facet> • <apex:actionSupport>
Exploring the View and Controller layers of
Visualforce
• Model view controller (MVC) is a software architecture pattern
which separates the representation of information from the
user’s interaction with it.
• SFDC MVC pattern contains below three modules:
• Model
• View
• Controller
• Model: What schema and data does salesforce uses to
represent the system completely. In salesforce, we can say
that sObjects are the model as every entity in salesforce is
mapped to some sObject.
• View: How the schema and data is represented. Visualforce is
used to present the data to users.
• Controller: How the interface actions. Controllers are used to
perform the actions whenever users interact with visual force.
SFDC MVC
• View Layer of Model View controller
• Visual Force pages, Page Layouts, Tabs
• Controller part in Model View controller
• Workflows, Apex Classes, Triggers
• Model Layer of Model View Controller .
• Objects, Fields, Relationships
Standard Controller
• built-in controllers are referred to generally as standard controllers,
or even the standard controller.
• built-in controllers
• to handle standard actions and data access
• providing simple and tight integration with the Lightning Platform database
• Most standard and all custom objects have standard controllers that
can be used to interact with the data associated with the object
Display Data from a Single Record
• Add the standard controller for accounts to the page, and then
reference account fields to display a record’s data.
<apex:page standardController="Account">
<apex:pageBlock title="Account Summary">
<apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Find a Record ID and Add It to the Request URL
Cntd…..
<apex:page>
<apex:pageBlock title="Account Summary">
<apex:pageBlockSection>
$A.get("e.force:navigateToURL").setParams( {"url":
"/apex/pageName?&id=00141000004jkU0AAI"}).fire();
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Display Fields from Related Records
• viewing the object details for Account,
• Account Owner, and that its type is Lookup(User).
• https://trailhead.salesforce.com/content/learn/modules/visualforce_
fundamentals/visualforce_standard_list_controllers
Display a List of Records
<apex:page standardController="Contact" recordSetVar="contacts">
<apex:pageBlock title="Contacts List">
<!-- Contacts List -->
<apex:pageBlockTable value="{! contacts }" var="ct">
<apex:column value="{! ct.FirstName }"/>
<apex:column value="{! ct.LastName }"/>
<apex:column value="{! ct.Email }"/>
<apex:column value="{! ct.Account.Name }"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Add List View Filtering to the List
Filter:
<apex:selectList value="{! filterId }" size="1">
<apex:selectOptions value="{! listViewOptions }"/>
<apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>
Add Pagination to the List
<!-- Pagination -->
<table style="width: 100%"><tr>
<td>
<!-- Page X of Y -->
</td>
<td align="center">
<!-- Previous page -->
<!-- Next page -->
</td>
<td align="right">
<!-- Records per page -->
</td>
</tr></table>
Create & Use Custom Controllers
• Custom controllers
• contain custom logic and data manipulation that can be used by a Visualforce
page.
• For example, a custom controller
• can retrieve a list of items to be displayed, make a callout to an external web service,
validate and insert data, and more—and all of these operations will be available to the
Visualforce page that uses it as a controller.
• https://trailhead.salesforce.com/content/learn/modules/visualforce_fundam
entals/visualforce_custom_controllers