Professional Documents
Culture Documents
========================
Object --> Table:
Tab: (GUI)
Business Logic: (Class)
2. We can't Change the Font, Color, Size and Style of the Standard User
Interface Controls.
By using Visualforce Programming, we can design the Customized User Interface based
on the application requirement with rich look and feel.
Visualforce supports all the Standard Web Technologies like "HTML, DHTML, CSS, Java
Script, JQuery, JScript, Angular JS, Knockout JS, Extension JS, Backbone JS,
MeanStack, Flash Scripting,..etc".
Visualforce supports the XML Style of syntax. Where each Starting Tag should have
the corresponding ending tag.
Visualforce provides the Real-Time Development style, where we can Write the Code,
Compile, Save, Execute and View the results in a single window.
Each Visualforce Page code will be get Compiled by using a Compiler called as "Page
Compiler" and will get executed by using a Runtime Engine "Page Renderer".
Note: All the Visualforce Pages code will get resides inside the "ApexPage" object.
We can query the Page code as below.
Ex:
Select id, name, markup from ApexPage
Visualforce Components:
=======================
Each Visualforce Page Contains 2 Components.
1. Visualforce Markup:
It is a Tag based programming, which is used to design the Customized
user interfaces with attractive look and feel.
Note: Each Visualforce Page Tag name should be pre-fix with the word
"apex".
Ex:
<apex:Page>
....
....
</apex:Page>
<apex:form>
...
...
</apex:form>
<apex:SectionHeader>
...
...
</apex:SectionHeader>
2. Visualforce Controller
Each Visualforce Page contains a Controller Class, which contains the
Business Logic to be get referenced inside the Page. It can be implemented by using
"Apex programming".
1. Standard Controller
2. Custom Controller
3. Extension Controller
Tag Hierarchy:
--------------
Page Tag (<apex:Page>)
|
|
| ---> SectionHeader Tag (<apex:SectionHeader>)
|
|
---> Form Tag (<apex:Form>)
|
|
---> PageBlock Tag (<apex:PageBlock>)
|
|
| ---> PageBlockButtons Tag
(<apex:PageBlockButtons>)
| |
| |
| | ---> CommandButton
(<apex:CommandButton>)
| |
| |
| ---> CommandLink
(<apex:CommandLink>)
|
|
---> PageBlockSection Tag
(<apex:PageBlockSection>)
|
|
| ---> PageBlockSectionItem
Tag (<apex:PageBlockSectionItem>)
| |
| |
| | ---> Input
Controls (<apex:InputText>)
| |
| |
| --->
Output Controls (<apex:OutputText>)
|
|
| ---> Input Controls (<apex:InputText>)
|
|
---> Output Controls (<apex:OutputText>)
Ex:
<apex:page >
Welcome to Visualforce Programming. <br/> This is
my First Visualforce Page.
</apex:page>
Syntax:
https://<ServerNumber>.salesforce.com/apex/<PageName>
Ex:
https://ap16.salesforce.com/apex/SampleThirdPage
Note:
To Create the Visualforce Page from the URL format, we have
to enable "Development Mode" CheckBox as below.
Example:
<apex:page controller="SampeThirdController" >
Welcome to Visualforce Programming. <br/><br/> <b>This is
my Third Visualforce Page.</b>
<br/><br/> <b> This Page has been designed by using URL
Format. </b>
</apex:page>
Tag Properties:
===============
Page Tag (<apex:Page>):
-----------------------
Properties:
1. Setup = "Boolean"
2. SideBar = "Boolean"
3. ShowHeader = "Boolean"
4. TabStyle = "SObjectName"
Ex:
<apex:page setup="false" sidebar="false" showheader="true"
tabStyle="Recruiter__c" >
</apex:page>
5. RenderAs = "pdf"
6. Rendered = "Boolean"
7. ContentType ="Application/MSWord#<FileName.doc>"
Ex:
<apex:page
contentType="Application/msword#Batch330File.doc" setup="false" sidebar="false"
showheader="true" tabStyle="Recruiter__c" >
Welcome to Visualforce Programming. <br/><br/> This is
my Third Visualforce Page designed by using URL Format.
<br/><br/> <b>This Page is used to represent the Tag
properties.</b>
</apex:page>
8. ReadOnly = "Boolean"
9. Action = "{! <MethodName> }"
10. StandardController = "StandardSObjectClassName"
11. Controller = "Custom Class Name"
12. Extensions = "Extension Class Names"
Ex:
<apex:page setup="false" sidebar="false" showheader="true"
tabStyle="Recruiter__c" >
<apex:sectionHeader title="Position Edit" subtitle="New
Position"/>
</apex:page>
Properties:
1. Id = "referenceName"
2. Rendered = "Boolean"
Ex:
<apex:page setup="false" sidebar="false" showheader="true"
tabStyle="Recruiter__c" >
<apex:sectionHeader title="Position Edit" subtitle="New
Position"/>
<apex:form >
</apex:form>
</apex:page>
Note:
A Visualforce page can have one or more PageBlocks. In Each PageBlock,
we can represent the different content with different format.
Properties:
1. Id = "referenceName"
2. Title = "PageBlock Title"
3. Rendered = "Boolean"
Ex:
<apex:page setup="false" sidebar="false" showheader="true"
tabStyle="Recruiter__c" >
<apex:sectionHeader title="Position Edit" subtitle="New Position"/>
<apex:form >
</apex:form>
</apex:page>
Note:
This should be always a Child Component to "PageBlock".
Properties:
1. Title = "Title for the Section"
2. Columns="Integer (1 / 2 / 3/ 4/ 5/ 6/....)"
3. Collapsible="Boolean"
4. Id = "referenceName"
5. Rendered = "Boolean"
Ex:
<apex:page setup="false" sidebar="false" showheader="true"
tabStyle="Recruiter__c" >
<apex:sectionHeader title="Position Edit" subtitle="New Position"/>
<apex:form >
Properties:
1. Title = "Title for the Buttons Section"
2. Location = "Top / Bottom / Both (Default)"
3. Rendered = "Boolean"
Properties:
1. Id = "referenceName"
2. Value = "Caption for the Button"
3. Action = "{! <MethodName> }"
4. Rendered = "Boolean"
5. ReRender = "ComponentReferenceNames"
Ex:
<apex:page setup="false" sidebar="false" showheader="true"
tabStyle="Recruiter__c" >
<apex:sectionHeader title="Position Edit" subtitle="New Position"/>
<apex:form >
<apex:pageblockButtons location="both">
<apex:commandButton value="Save"/>
<apex:commandButton value="Save & New"/>
<apex:commandButton value="Delete"/>
<apex:commandButton value="Search"/>
<apex:commandButton value="Cancel"/>
</apex:pageblockButtons>
</apex:form>
</apex:page>
Properties:
1. Id = "referenceName"
2. Value = "Caption for the Button"
3. Action = "{! <MethodName> }"
4. Rendered = "Boolean"
5. ReRender = "ComponentReferenceNames"
Ex:
<apex:page setup="false" sidebar="false" showheader="true"
tabStyle="Recruiter__c" >
<apex:sectionHeader title="Position Edit" subtitle="New Position"/>
<apex:form >
<apex:pageblockButtons location="both">
</apex:form>
</apex:page>
Visualforce Controllers:
------------------------
Visualforce Page ---> Controller Class. (Business Logic)
3 Types of Controllers
1. Standard Controller
2. Custom Controller
3. Extension Controller
Standard Controller:
====================
ORM:
Ex:
Account Object:
Methods:
--------
Public void Save()
{
// This method will save the record
inside the object and will re-direct the user to the detailed page of the record.
}
Pagination Methods:
--------------------
Public void First()
{
// It will load the First Page Records in
the Pagination.
}
Note:
By using StandardController, We can reference all the Standard
Functionalities inside the VF Page.
i.e. Instead of Writing the Business Logic by our own, we can use the
existing Business Logic given by Salesforce, so that we can avoid the number of
lines of Code.
Syntax:
<apex:Page StandardController = "<ClassName>" .....>
...
...
</apex:Page>
Ex:
<apex:Page StandardController = "Account" ....>
...
...
</apex:Page>
Custom Controller:
==================
Upon implementing the application features, if the Standard Functionalities are not
suitable for the requirement. Then we can build our own Custom Business Logic based
on the application requirement, and can be referenced inside the VF page by using
"Custom Controller".
We have the specify the Class name inside the Page Tag by using "Controller"
property as below.
Syntax:
<apex:Page Controller = "<Custom Class Name>" .....>
...
...
</apex:Page>
Ex:
Public Class AccountsSearchHelper
{
Public void SearchAccounts()
{
// Write the Business Logic to Search Account Records.
}
}
</apex:Page>
Extension Controller:
=====================
By using this feature, we can reference both Standard Functionalities and Custom
Functionalities inside the VF Page.
Note:
We can use Only One StandardController inside the Page and we can reference
One / More Extension Controller Classes inside the Page.
Syntax:
<apex:Page StandardController="<ClassName>" Extensions="<Class1>,<Class2>,.."
>
..
..
<apex:Page>
Ex:
Public Class AccountsHelper
{
Public void CheckDuplicateAccounts()
{
// Write the Business Logic to Eliminate the Duplicate Accounts.
}
}
</apex:Page>
Properties:
1. ID = "referenceName"
2. Value = "{!<StandardClassName>.<FieldName>}"
3. Rendered = "Boolean"
4. Required = "Boolean"
Note:
While binding a Field Name to the tag, it will verify the field DataType and
Properties. Based on the field properties, it will provide the respective visual
appearance on the user interface.
Note:
Upon representing the field tags on the Visualforce page, we have to add the
corresponding Controller Class inside the Page Tag by using "StandardController"
property.
Ex:
<apex:Page StandardController="Account">
<apex:inputfield Value="{!Account.Name}"/>
<apex:inputfield Value="{!Account.Rating}"/>
<apex:inputfield value="{!Account.Pan_Number__C}"/>
</apex:Page>
UseCase:
========
Design a Visualforce page to Create New Account Records inside the Account
object.
VF Page Code:
-------------
<apex:page StandardController="Account" setup="false" sidebar="false"
showheader="true" tabStyle="Customer__c">
<apex:sectionHeader title="Account Edit" subtitle="New Account"/>
<apex:form >
<apex:pageblock title="Account Edit">
<apex:pageblockButtons location="Both">
<apex:commandButton value="Save" action="{!Save}"/>
<apex:commandButton value="Save & New" action="{!Save}"/>
<apex:CommandButton value="Cancel" action="{!Cancel}"/>
</apex:pageblockButtons>
i.e. We can override the Standard Buttons controls to re-direct the user to our own
custom Visualforce pages as below.
Assignments:
============
1. Design a Visualforce page to Create the Lead Records inside the Object,
and
add the respective Action Methods. And Override the Standard New Button
Control for the Lead Object.
Detailed Page:
==============
To design the detailed page of the record through VF programming, we have to use
"<apex:Detail> tag".
By using this tag we can design the detailed page of the record and we can
represent the record information along with the required related lists also.
Properties:
1. Title = "Boolean"
This property is used to indicate whether the record title to be get
visible on the detailed page of the record or not.
2. InlineEdit = "Boolean"
This property is used to indicate the detailed page can have the Inline
Editing feature or not.
3. ShowChatter = "Boolean"
This property is used to indicate the page can have the Chatter Feed or
not.
4. RelatedList = "Boolean"
This property is used to indicate the page can show the RelatedList
records or not.
Note: The Detail tag should be always placed outside of the "Form Tag".
UseCase:
========
Design a Visualforce Page to represent the detailed page of the Account
Records.
VF Page Code:
-------------
<apex:page StandardController="Account" setup="false" sidebar="false"
showheader="true" tabStyle="Recruiter__c" >
<chatter:feedWithFollowers entityId="{!Account.ID}"/>
</apex:page>
Syntax:
https://<ServerNumber>.Salesforce.com/apex/<PageName>?
Id=<accountRecordID>
Ex:
https://c.ap15.visual.force.com/apex/AccountRecordDetailPage?id=0012v00002pynYX
Each RelatedList tag is used to represent only one RelatedList on the Page.
To represent the multiple relatedLists on the detailed page, we have to use
multiple RelatedList tags.
Properties:
1. List = "RelatedListName"
This property is used to specify the RelatedList name, to be get
visible on the detail page.
2. PageSize = "Integer"
This property is used to indicate the number of records to be get
visible in the relatedList at a time.
3. Rendered = "Boolean"
UseCase:
========
Design a VF Page to represent the Detailed Page of the Account Record, by
adding the required RelatedLists on the Page.
And make the Custom Detailed Page should be the default page to represent the
Account Records. (i.e. Override the "Standard View Button")
VF Page Code:
-------------
<apex:page StandardController="Account" setup="false" sidebar="false"
showheader="true" tabStyle="Recruiter__c" >
<chatter:feedWithFollowers entityId="{!Account.ID}"/>
Tab Controls:
=============
By using this feature, we can represent the data in the form of TabControls. VF
provides the below 2 Tags to be used to prepare the Tab Controls on the page.
Properties:
1. SelectedTab = "TabName / Tab ReferenceName"
By using this property we can indicate, which tab should be
"Active / Selected" by default while loading the TabControl / Panel.
2. SwitchType = "ajax"
This property is used to refresh the currently selected tab upon
click on the Tab. So that we can improve the application performance.
Ex:
<apex:TabPanel SelectedTab="TabName" SwitchType="ajax">
...
...
</apex:TabPanel>
Note:
This tag should be always a Child Component to the "TabPanel".
Properties:
1. Label = "Caption for the Tab"
This property is used to specify the Caption for the Tab.
2. Name = "ReferenceName"
This property is used to specify the unique reference name to
identify the tab inside the TabPanel.
3. Rendered = "Boolean"
UseCase:
========
Design a VF Page to represent the Detailed Page of the Account Record, by
representing the related lists in the tab format.
And make the Custom Detailed Page should be the default page to represent the
Account Records. (i.e. Override the "Standard View Button")
VF Page Code:
-------------
<apex:page standardController="Account" setup="false" sidebar="false"
showHeader="true" tabStyle="Customer__c" >
<apex:TabPanel switchtype="ajax" >
</apex:TabPanel>
</apex:page>
Custom Controller:
==================
Upon performing the operations by using Visualforce Programming, if the Standard
Functionalities are not suitable, then we can Prepare our own business logic and
can be referenced inside the VF Page by using "Custom Controller".
i.e. We can Prepare our own Custom Class by implementing the required business
logic and can be invoked by using Button Controls on the VF Page.
Upon using the Custom Controller, we have to follow the below steps..
Step 1: Design a Visualforce Page with the required visual appearance controls.
Step 2: Implement the Custom Business Logic by creating the Apex Class and define
the required variables inside the Class and implement the required
methods with th business logic.
Note:
Define the required variables, Collections and Objects can be
referenced inside the VF Page with "GET and SET" accessors.
GET --> Used to Access the value from the Visualforce page.
SET --> Used to Set / Assign the Value from the Visualforce Page.
Ex:
Public Class CalculatorController
{
// Define the Variables, Objects, Collections,...etc.
Public integer customerCode{get;set;}
Public string customerName{get;set;}
Public List<Account> lstAccounts{get;set;}
Step 3: Reference the Custom Class inside the VF Page by using "Controller"
attribute.
Syntax:
<apex:Page Controller="CalculatorController" >
..
..
</apex:Page>
UseCase:
========
Design a Visualforce Page to represent the Product Details on the Visualforce
Page.
VF Page Code:
-------------
<apex:page controller="ShowProductDetailsController" >
Product Code is...: {!productCode} <br/>
Product Name is...: {!productName} <br/>
Manufacturer Name is...: {!manufacturerName} <br/>
Unit Price is....: {! unitPrice} <br/>
Manufacturing Date is...: {!manufacturingDate} <br/>
Expiry Date is....: {!expiryDate} <br/>
Product is Available? ....: {!isInStock}
</apex:page>
Controller Class:
-----------------
public class ShowProductDetailsController
{
Public integer productCode{get;set;}
Public string productName{get;set;}
Public string manufacturerName{get;set;}
Public Decimal unitPrice{get;set;}
Public Date manufacturingDate{get;set;}
Public Date expiryDate{get;set;}
Public Boolean isInStock{get;set;}
}
Assignments:
============
1. Design a Visualforce Page to represent the Customer Details on the Page.
UseCase:
========
Design a Visualforce Page to represent the Product Details on the Visualforce
Page. Assign the Values for the variables by using "Constructor".
VF Page Code:
-------------
<apex:page controller="ShowProductDetailsController" >
Product Code is...: {!productCode} <br/>
Product Name is...: {!productName} <br/>
Manufacturer Name is...: {!manufacturerName} <br/>
Unit Price is....: {! unitPrice} <br/>
Manufacturing Date is...: {!manufacturingDate} <br/>
Expiry Date is....: {!expiryDate} <br/>
Product is Available? ....: {!isInStock}
</apex:page>
Controller Class:
-----------------
public class ShowProductDetailsController
{
Public integer productCode{get;set;}
Public string productName{get;set;}
Public string manufacturerName{get;set;}
Public Decimal unitPrice{get;set;}
Public Date manufacturingDate{get;set;}
Public Date expiryDate{get;set;}
Public Boolean isInStock{get;set;}
UseCase:
========
Design a Visualforce Page to Create an Account Record inside the object while
loading the Page.
VF Page Code:
-------------
<apex:page action="{!CreateAccountRecord}"
controller="CreateNewAccountRecordController" >
{!recordResult}
</apex:page>
Controller Class:
-----------------
public class CreateNewAccountRecordController
{
Public string recordResult{get;set;}
insert acc;
if(acc.id != null)
recordResult = 'Account Record Inserted Successfully with id...: '+
acc.id;
else
recordResult = 'Something went wrong while inserting record.';
}
}
Note:
While Loading the Page, We can't write the DML Statements inside the
Constructor.
i.e. Constructor doesn't supports the DML Statements. But it will supports
SOQL Queries.
Properties:
1. Id = "referenceName"
2. Label = "Label for the TextBox"
3. html-placeholder = "Watermark Text inside the TextBox"
4. Rendered = "Boolean"
5. Value = "{! <VariableName> }"
UseCase:
========
Design a Visualforce Page to implement the Basic Calculator. And perform the
Operations by using the Button Controls.
VF Page Code:
-------------
<apex:page controller="BasicCalculatorController" setup="false" sidebar="false"
showHeader="true" tabStyle="Hiring_Manager__c" >
<apex:sectionHeader title="Calculator" subtitle="Basic Calculator"/>
<apex:form >
<apex:pageblock title="Basic Calculator Block">
<apex:pageblockButtons location="bottom">
<apex:commandButton value="Addition" action="{!Addition}"
rerender="res"/>
<apex:commandButton value="Subtraction" action="{!Subtraction}"
rerender="res"/>
<apex:commandButton value="Multiplication" action="{!Multiply}"
rerender="res"/>
<apex:commandButton value="Division" action="{!Division}"
rerender="res"/>
<apex:commandButton value="Modulus" action="{!Modulus}"
rerender="res"/>
</apex:pageblockButtons>
Controller Class:
-----------------
public class BasicCalculatorController
{
Public integer firstNumber{get;set;}
Public integer secondNumber{get;set;}
Public integer result{get;set;}
Ex:
<apex:form>
<apex:PageMessages id="errors"/>
</apex:form>
Upon representing the error messages on the VF Page, each Error message contains
the below 2 parts.
1. Error Icon:
Visualforce provides the below Error Icons
ApexPages.Severity.CONFIRM
ApexPages.Severity.INFO
ApexPages.Severity.WARNING
ApexPages.Severity.ERROR
ApexPages.Severity.FATAL
We can represent the error message on the VF Page through Apex Programming as
below.
Syntax:
ApexPages.AddMessage(new ApexPages.Message(<Error Icon>,<Error
Description>));
Ex:
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.CONFIRM,
'Operation
Completed Successfully.'));
UseCase:
========
Design a Visualforce Page to implement the Basic Calculator. And perform the
Operations by using the Button Controls. Represent the Error Messages on the Page,
if some thing went wrong.
VF Page Code:
-------------
<apex:page controller="BasicCalculatorController" setup="false" sidebar="false"
showHeader="true" tabStyle="Hiring_Manager__c" >
<apex:sectionHeader title="Calculator" subtitle="Basic Calculator"/>
<apex:form >
<apex:PageMessages id="errors"></apex:PageMessages>
Database Interaction:
=====================
By using VF Programming, we can interact with the Salesforce Objects, we can
perform all the DML operations on the object records and we can fetch the records
from the object by using SOQL Queries.
To represent the result records on the VF Page in Tabular format, we have to use
"PageBlockTable"Tag.
Note:
This should be a Child Component to the "PageBlock".
Properties:
1. Id = "referenceName"
2. Rendered = "Boolean"
3. Value = "{! <ListCollection / DataSource> }"
4. Var = "reference for each record"
Properties:
1. ID = "referenceName"
2. Rendered = "Boolean"
3. HeaderValue = "Caption for the Column"
4. Value = "{! <refName>.<FieldName> }"
UseCase:
========
Design a Visualforce Page to represent all the Account Records in the Tabular
format while loading the page.
VF Page Code:
-------------
<apex:page controller="ShowAllAccountRecordsController" setup="false"
sidebar="false" showHeader="true" tabStyle="Position__c" >
<apex:sectionHeader title="Accounts" subtitle="All Accounts"/>
<apex:form >
<apex:pageblock title="All Accounts : ( {!lstAccounts.size} ) ">
</apex:pageblock>
</apex:form>
</apex:page>
Controller Class:
-----------------
public class ShowAllAccountRecordsController
{
Public List<Account> lstAccounts{get;set;}
// Prepare Default Constructor..
Public ShowAllAccountRecordsController()
{
lstAccounts = new List<Account>();
Properties:
1. ID = "referenceName"
2. Rendered = "Boolean"
3. Value = "<PathOfTargetPageName>"
4. Target = "_blank / _New"
Ex:
<apex:OutputLink value="http://www.salesforce.com" target="_blank">
Click Here </apex:OutputLink>
UseCase:
========
Design a Visualforce Page to represent all the Account Records in the Tabular
format while loading the page.
VF Page Code:
-------------
<apex:page controller="ShowAllAccountRecordsController" setup="false"
sidebar="false" showHeader="true" tabStyle="Position__c" >
<apex:sectionHeader title="Accounts" subtitle="All Accounts"/>
<apex:form >
<apex:pageblock title="All Accounts : ( {!lstAccounts.size} ) ">
Controller Class:
-----------------
public class ShowAllAccountRecordsController
{
Public List<Account> lstAccounts{get;set;}
UseCase:
========
Design a Visualforce Page to search for the Account Records based on the
specified characters at runtime. Match the input text with "Account Name".
VF Page Code:
-------------
<apex:page controller="SearchAccountsController" setup="false" sidebar="false"
showheader="true" tabStyle="Customer__c" >
<apex:sectionHeader title="Accounts" subtitle="Search Accounts"/>
<apex:form >
<apex:Pagemessages id="errors"></apex:Pagemessages>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Class:
-----------------
public class SearchAccountsController
{
Public string searchText{get;set;}
Public List<Account> lstAccounts{get;set;}
Page Redirection:
=================
By using this feature, we can re-direct the user from one Visualforce page to
another upon click on the button controls.
Ex:
SourcePage <-- To ---> TargetPage
Upon redirecting the user, we need to hold the address / details of the target page
to which the user is being re-directed.
To hold the address of the Target Page we have to use "PageReference" class.
PageReference Class:
--------------------
This class will holds the address of the specified Visualforce page.
Syntax:
PageReference <ObjectName> = new PageReference('/apex/<TargetPageName>');
Ex:
PageReference pgRef = new PageReference('/apex/TargetPage');
To re-direct the user to the specified page, we have to use "SetRedirect()" method.
Syntax:
<objectName>.SetRedirect(true);
Ex:
pgRef.SetRedirect(true);
UseCase:
========
Design Two Visualforce Pages and Re-direct the users from One Visualforce
page to another.
Source Page:
------------
VF Page Code:
<apex:page controller="SourcePageController" setup="false" sidebar="false"
showheader="true" tabStyle="Solution" >
<apex:sectionHeader title="Page Redirection" subtitle="Source Page"/>
<apex:form >
<apex:PageBlock title="Source Page Block">
<apex:pageblockButtons location="top">
<apex:commandButton value="Next Page" action="{!
GotoTargetPage}"/>
</apex:pageblockButtons>
</apex:PageBlock>
</apex:form>
</apex:page>
Controller Class:
public class SourcePageController
{
Public PageReference GotoTargetPage()
{
PageReference pgRef = new PageReference('/apex/TargetPage');
return pgRef.SetRedirect(true);
}
}
Target Page:
------------
VF Page Code:
<apex:page controller="TargetPageController" setup="false" sidebar="false"
showheader="true" tabStyle="Order" >
<apex:sectionHeader title="Page Redirection" subtitle="Target Page"/>
<apex:form >
<apex:PageBlock title="Target Page Block">
<apex:pageblockButtons location="top">
<apex:commandButton value="Previous Page" action="{!
GotoPreviousPage}"/>
</apex:pageblockButtons>
</apex:PageBlock>
</apex:form>
</apex:page>
Controller Class:
public class TargetPageController
{
Public PageReference GotoPreviousPage()
{
PageReference pgRef = new PageReference('/apex/SourcePage');
return pgRef.SetRedirect(true);
}
}
QueryString:
============
QueryString is used to pass the values from one Visualforce page to another upon
page re-direction.
By using QueryString, we can supply either One / More values from one page to
another.
Note:
QueryString will add the parameters / values to the URL. Each Parameter
should have a "Key" and a "Value".
Syntax:
PageReference <objectName> = new
PageReference('/apex/<PageName>?
<paramName>=<Value>');
Ex:
string searchText = 'test';
PageReference pgRef = new PageReference('/apex/TargetPage?
sText='+searchText);
Note:
We can add the multiple parameters to the QueryString by using a separator
"&".
Upon passing the parameters to the Visualforce Page, it will append the
Values inside the URL.
Syntax:
<DataType> <value> =
ApexPages.CurrentPage().GetParameters().Get('paramName');
Ex:
String customerName =
ApexPages.CurrentPage().GetParameters().Get('aName');
string customerRating =
ApexPages.CurrentPage().GetParameters().Get('aRating');
UseCase:
========
Design a Visualforce Page to Search for the Lead Records based on the User Input by
compare with the Lead LastName.
VF Page Code:
-------------
<apex:page controller="LeadSearchResultsController" setup="false" sidebar="false"
showheader="true" tabStyle="Recruiter__c" >
<apex:sectionHeader title="Search Results" subtitle="Lead Search Results"/>
<apex:form >
<apex:PageBlock title="Search Results : ( {!lstLeads.Size} )">
<apex:PageblockButtons location="top">
<Apex:commandButton value="Search Again" action="{!GotoSearchPage}"/>
</apex:PageblockButtons>
Controller Class:
-----------------
public class LeadSearchResultsController
{
Public List<Lead> lstLeads{get;set;}
// Default Constructor..
Public LeadSearchResultsController()
{
lstLeads = new List<Lead>();
ViewState:
==========
Base64Encoding format.
Size: 135 KB
Your Name
|
--> My Settings
|
--> Personal
|
--> Advanced User Details
|
--> CheckBox:
Graduation:
|
--> Looking for Job
|
--> Resume.
|
--> Job Portals.
|
--> Create an Account. (Sign Up)
These keywords can be applicable at the Class level, Upon Creating an apex Class,
we can specify either "WithSharing / Without Sharing".
Syntax:
[Access Specifier] [With Sharing / Without Sharing] Class <ClassName>
{
// Write the Business Logic..
}
Ex:
Public Class AccountsHelper --> Without Sharing
{
// Written Business Logic..
}
Pagination:
===========
Upon representing the records on the VF Page, it can represent max. of 1,000
records on the Page.
To represent more number of records on the Page, we have the assign the property
"ReadOnly = true" inside the Page Tag. Then it will enhance the VF Page capability
to show max. of 10,000 records at a time.
Note: But, ReadOnly property will prevent the DML operations on the Page.
To avoid this problem, to show the more number of records on the page we can use
"Pagination / Paging".
We can divide all the records received from the object into the various smaller
pieces called as "Pages". And we can represent each Page on the VF Page at a time.
And the user can navigate all the records from First To Last and Vice-Versa by
using "Navigation Buttons".
Methods:
--------
Syntax:
StandardSetController sController = new
StandardSetController(Database.getQueryLocator([SOQL
Query]));
1. SetPageSize(Integer):
2. Integer ResultSize():
3. First():
4. Next():
5. Previous():
6. Last():
7. Boolean HasNext():
8. Boolean HasPrevious():
9. Integer PageNumber():
VF Page Code:
-------------
<apex:page controller="AccountRecordsPaginationController" setup="false"
sidebar="false" showheader="true" tabStyle="Customer__c">
<apex:SectionHeader title="Pagination" subtitle="Accounts Pagination"/>
<apex:form >
<apex:pageblock title="Account Records" id="pgBlock">
<apex:PageBlockTable value="{!accounts}" var="acc">
<apex:column headerValue="Account Name">
<apex:outputLink value="/{!acc.id}" target="_blank"> {!acc.Name}
</apex:outputLink>
</apex:column>
<apex:Column value="{!acc.Rating}"/>
<apex:column value="{!acc.Industry}"/>
<apex:column value="{!acc.Annualrevenue}"/>
<apex:column value="{!acc.Type}"/>
<apex:column value="{!acc.ownership}"/>
<apex:column value="{!acc.phone}"/>
<apex:column value="{!acc.fax}"/>
<apex:column value="{!acc.Active__c}"/>
</apex:PageBlockTable>
<br/><br/>
<center> <b>
<apex:outputlabel > {! (setController.PageNumber -1)*
setController.PageSize + 1} to {!setController.PageNumber* setController.PageSize}
Of {!setController.ResultSize}</apex:outputlabel>
<apex:commandLink value="First" action="{!setController.First}"
rerender="pgBlock" rendered="{!setController.hasPrevious}"/>
<apex:commandLink value="Previous" action="{!setController.Previous}"
rerender="pgBlock" rendered="{!setController.hasPrevious}"/>
<apex:commandLink value="Next" action="{!setController.Next}"
rerender="pgBlock" rendered="{!setController.HasNext}" />
<apex:commandLink value="Last" action="{!setController.Last}"
rerender="pgBlock" rendered="{!setController.HasNext}"/>
</b></center>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Class:
-----------------
public class AccountRecordsPaginationController
{
Public ApexPages.StandardSetController setController
{
Get
{
if(setController == null)
{
setController = new
ApexPages.StandardSetController(Database.getQueryLocator([Select id, name, rating,
industry, annualrevenue,
Extension Controller:
=====================
StandardController --> Standard Functionalities
UseCase:
========
Design a Visualforce Page to Insert the Hiring Manager Records inside the
object.
1. Upon Saving the Record, is should maintain the Uniqueness based on
the
Hiring Manager Name and Contact Number Combination.
2. If any Duplicate Records Found, then show the Error Message on the
Page. Else insert the Record as it is.
3. Upon Click on the Cancel Button, Cancel the Current Operation.
VF Page Code:
-------------
<apex:page StandardController="Hiring_Manager__c"
Extensions="NewHiringManagerRecordExtension" setup="false" sidebar="false"
showheader="true" tabStyle="Customer__c">
<apex:sectionHeader title="Hiring Manager Edit" subtitle="New Hiring Manager"/>
<apex:form >
<apex:pagemessages id="errors"></apex:pagemessages>
</apex:PageBlock>
</apex:form>
</apex:page>
Controller Class:
-----------------
public class NewHiringManagerRecordExtension
{
Hiring_Manager__C hrRecord;
{
hrRecord = (Hiring_Manager__C) controller.GetRecord();
}
if(recordsCount > 0)
{
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Error,
'Duplicate Records Found with Same Details. Record Cannot be acceptable.'));
}
else
{
insert hrRecord;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Confirm,
'Hiring Manager Record Inserted Successfully.'));
}
}
}
Assignment:
===========
Create a Visualforce Page to Search for the Account Records based on the
specified Name in the search TextBox.
Wrapper Classes:
================
UseCase:
========
Design a Visualforce Page to represent the Account Records and Contact
Records and Lead Records inside a Single Table.
1. Represent the Record Name in the form of a "HyperLink".
2. Re-direct the user to the detailed page of the record upon click on
the record name.
Wrapper Class:
--------------
public class CustomWrapper
{
Public ID recordID{get;set;}
Public string firstName{get;set;}
Public string lastName{get;set;}
Public string designation{get;set;}
Public string ratingValue{get;set;}
Public string industryName{get;set;}
public Decimal annualRevenueValue{get;set;}
Public string cityName{get;set;}
Public string stateName{get;set;}
Public string countryName{get;set;}
Public string phoneNumber{get;set;}
Public string faxNumber{get;set;}
Public Boolean isSelected{get;set;}
// Prepare a Constructor to Convert the Account Record into our Custom Type.
Public CustomWrapper(Account acc, Boolean selection)
{
recordID = acc.id;
lastName = acc.Name;
ratingValue = acc.Rating;
industryName = acc.Industry;
annualRevenueValue = acc.AnnualRevenue;
cityName = acc.BillingCity;
stateName = acc.BillingState;
countryName = acc.BillingCountry;
phoneNumber = acc.Phone;
faxNumber = acc.Fax;
isSelected = selection;
}
// Prepare a Constructor to Convert the Lead Record into our Custom Type.
Public CustomWrapper(Lead ld, Boolean selection)
{
recordID = ld.id;
firstName = ld.FirstName;
lastName = ld.LastName;
ratingValue = ld.Rating;
industryName = ld.Industry;
phoneNumber = ld.Phone;
faxNumber = ld.Fax;
cityName = ld.City;
stateName = ld.State;
countryName = ld.Country;
designation = ld.Title;
isSelected = selection;
}
// Prepare a Constructor to Convert the Contact Record into our Custom Type.
Public CustomWrapper(Contact con, Boolean selection)
{
recordID = con.id;
firstName = con.FirstName;
lastName = con.LastName;
designation = con.Title;
phoneNumber = con.Phone;
faxNumber = con.Fax;
cityName = con.MailingCity;
stateName = con.MailingState;
countryName = con.MailingCountry;
isSelected = selection;
}
}
VF Page Code:
-------------
<apex:page action="{!GetRecords}" controller="CustomWrapperDetailsController"
setup="false" sidebar="false" showheader="true" tabstyle="Customer__c" >
<apex:sectionHeader title="Custom Wrapper" subtitle="AccountLeads Wrapper"/>
<apex:form >
<apex:Pageblock title="Custom Wrapper Block" id="pgBlock">
<apex:pageblockButtons location="top">
<apex:commandButton value="Select All" action="{!SelectAllRecords}"
rerender="pgBlock"/>
<apex:commandButton value="Un Select All" action="{!
UnSelectAllRecords}" rerender="pgBlock"/>
<apex:commandButton value="Delete"/>
</apex:pageblockButtons>
Controller Class:
-----------------
public class CustomWrapperDetailsController
{
Public List<CustomWrapper> lstWrapper{get;set;}
// Get the Records from the objects and store them into the collection.
Limit 20];
// Pass each Account record to Custom Wrapper Class, then it will prepare
the Custom Record.
for(Account acc : lstAccounts)
{
CustomWrapper cWrapper = new CustomWrapper(acc, false);
lstWrapper.Add(cWrapper);
}
// Pass each Contact record to Custom Wrapper Class, then it will prepare
the Custom Record.
for(Contact con : lstContacts)
{
CustomWrapper cWrapper = new CustomWrapper(con, false);
lstWrapper.Add(cWrapper);
}
List<Lead> lstLeads = [Select id, firstname, lastname, title, phone, fax,
industry, rating,
annualrevenue, city,
state, country
from Lead
Order
by lastname
Limit 20];
// Pass each Lead record to Custom Wrapper Class, then it will prepare the
Custom Record.
for(Lead ld : lstLeads)
{
CustomWrapper cWrapper = new CustomWrapper(ld, false);
lstWrapper.Add(cWrapper);
}
}
}
AJAX Controls:
==============
Properties:
1. Id = "referenceName"
2. Action = "{! <MethodName> }"
3. Interval = "Time in Seconds"
4. ReRender = "ComponentReferenceName"
Ex:
<apex:ActionPoller
Action="{! <MethodName> }"
Interval = "10"
ReRender="componentReferenceName"/>
UseCase:
========
Design a Visualforce Page to represent all the Case Records in the Tabular
format. And Refresh the Page for each 5 Seconds to load the latest Case Records.
VF Page Code:
-------------
<apex:page action="{!GetAllCaseRecords}" controller="ShowAllCaseRecordsController"
setup="false" sidebar="false" showheader="true" tabStyle="Solution">
<apex:sectionHeader title="Cases" subtitle="All Cases"/>
<apex:form >
<apex:actionPoller action="{!GetAllCaseRecords}" interval="5"
rerender="pgBlock"/>
Controller Class:
-----------------
public class ShowAllCaseRecordsController
{
Public List<Case> lstCases {get;set;}
Picklist Control:
=================
<apex:SelectList>
Properties:
1. Label = "Label information"
2. MultiSelect = "Boolean" (TRUE --> MultiSelect Picklist)
3. Size = "Integer"
4. Rendered = "Boolean"
5. Id = "referenceName"
6. Value = "{! <VariableName>}"
Note:
This tag should be a Child Component to the "SelectList" tag.
Properties:
1. ItemLabel = "Use to specify the Item / Element Label to be
visible in
the picklist control."
UseCase:
========
Design a Visualforce Page to represent the Picklist Control along with the
required options.
VF Page Code:
-------------
<apex:page setup="false" sidebar="false" showHeader="true" tabStyle="Order">
<apex:sectionHeader title="Picklist" subtitle="Input Controls"/>
<apex:form >
<apex:pageblock title="Picklist Controls Block">
<apex:pageblocksection title="Picklist Controls Section" columns="1"
collapsible="true">
</apex:pageblocksection>
</apex:pageblockSection>
</apex:pageblockSection>
<apex:selectoption itemlabel="India"
itemvalue="IND"></apex:selectoption>
<apex:selectoption itemlabel="United States"
itemvalue="USA"></apex:selectoption>
<apex:selectoption itemlabel="United Kingdom"
itemvalue="UK"></apex:selectoption>
<apex:selectoption itemlabel="Australia"
itemvalue="AUS"></apex:selectoption>
<apex:selectoption itemlabel="China"
itemvalue="CHN"></apex:selectoption>
<apex:selectoption itemlabel="Japan"
itemvalue="JPN"></apex:selectoption>
</apex:selectRadio>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
SelectOption Class. --> To add only one element to the picklist control through
programming.
Syntax:
SelectOption <objectName> = new SelectOption(<ItemValue>,<ItemLabel>);
Ex:
SelectOption option1 = new SelectOption('IND','India');
SelectOption option2 = new SelectOption('AUS','Australia');
SelectOption option3 = new SelectOption('JPN','Japan');
lstOptions.Add(option1);
lstOptions.Add(option2);
lstOptions.Add(option3);
<apex:SelectList>
<apex:SelectOptions Value="{!lstOptions}"/>
</apex:SelectList>
UseCase:
========
Design a Visualforce Page to Populate All the Account Record Names into the
Picklist Control upon loading the Page.
VF Page Code:
-------------
<apex:page controller="ShowAccountNamesController" setup="false" sidebar="false"
showheader="true" tabStyle="Solution">
<apex:sectionHeader title="Accounts" subtitle="All Accounts"/>
<apex:form >
<apex:pageblock title="Account Records">
<apex:pageblocksection title="Account Records" columns="1"
collapsible="true">
<apex:selectlist label="Account Record Names:" size="1"
multiselect="false">
<apex:selectOptions value="{!lstOptions}"></apex:selectOptions>
</apex:selectlist>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Class:
-----------------
public class ShowAccountNamesController
{
Public List<SelectOption> lstOptions{get;set;}
Public ShowAccountNamesController()
{
lstOptions = new List<SelectOption>();
VF Page Code:
-------------
<apex:page controller="ShowRelatedRecordsController" setup="false" sidebar="false"
showheader="true" tabStyle="Customer__c">
<apex:sectionHeader title="Picklist" subtitle="Related Records"/>
<apex:form >
<apex:pageblock title="Account Record Block">
<apex:pageblockSection title="Account Records Section" columns="1"
Collapsible="false">
<apex:selectlist label="Select the Account Name : " multiselect="false"
size="1" value="{!selectedAccountID}">
<apex:selectOptions value="{!lstOptions}"></apex:selectOptions>
</apex:selectlist>
</apex:pageblockSection>
</apex:pageblock>
</apex:form>
</apex:page>
Controller Class:
-----------------
public class ShowRelatedRecordsController
{
Public List<SelectOption> lstOptions {get;set;}
Public ShowRelatedRecordsController()
{
lstoptions = new List<Selectoption>();
SandBoxes
Deployments
Account
Contact
Opportunity
Case
Solution
...
Position__C
Candidate__C
Loan__c
Customer__c
...
...