Visualforce Pages
- Visualforce is a framework used by developers to build custom UI or custom pages on Salesforce platform. Although we have new tools in the market but Visualforce is still supported by Salesforce.
- Salesforce Classic is built using Visualforce pages.
- Visualforce creates front-end design pages using XML-like syntax, and Apex is used to execute the business logic in the backend.
- It is built on native force.com and lightning platform.
- Whatever is not possible with standard functionalities using declarative tools is built using VF.
- Major application is to override standard functionalities like standard buttons, tabs and pages or to add extra functionalities.
- Pages can be referenced and invoked via a unique URL.
- Visualforce follows the MVC architecture where View is the Pages, layout and Apex being the Controller and Model being the sObjects in Salesforce.
- All Visualforce pages will have extension of .vfp .To create a VF page, go to Developer Console->New->Page
- Visualforce pages use the same expression language as formulas — that is, anything inside {! } is evaluated as an expression that can access values from records that are currently in context. For example, you can display the current user’s first name by adding the {!$User.FirstName} merge field to a page.
<apex:page>
Hello {!$User.FirstName}!
s</apex:page>
- VF consists of: VF markup and Visualforce controllers.
a)VF markup — tag-based markup language similar to HTML. The markup defines the user interface components that are included on the page, and the way they appear. There are number of standard user interface component like Pageblock, pageblocksection, commandbutton to build the structure of page. Every VF page starts with <apex:page> and ends with </apex:page> tag.
Get Swati Gupta’s stories in your inbox
Join Medium for free to get updates from this writer.
b)Visualforce controllers — When a user interact with any of the component on the VF page, and wants to perform any server side database operation like save or fetch the data and display on UI we use Controllers. They provide business logic to VF pages and are written using Apex.
There are 3 types of controllers: Standard, Custom and Extension.
Standard controllers: Standard controllers are the default Controller’s provided by Force.com. They will have same logic and functionality using standard visualforce pages. No Apex code is required in Standard Controllers.
Syntax :- <apex:page standardcontroller =“Account”></apex:page>
Custom controller : When a developer needs different logic and functionality he/she may write their own Apex controller class. Custom controller’s will not provide default functions like standard controllers. Custom apex code must be written for custom controllers.
Syntax : <apex : page controller = “Mycontroller”></apex:page>
Extension controllers :If we want to use both custom controller functionality and standard controller functionality we use extension controllers. Extension Controllers begins with Standard controller and extended or overridden with custom controller with custom apex code.
Syntax :- <apex:page standardcontroller = “Account” extensions = “Testclass1, Testclass2?></apex:page>
Architecture:
The moment user save the page in browser it goes to the App server where it is compiled. After it is compiled successfully, it is saved to the metadata repository and is rendered as HTML to browser. Any errors in page will display in the browser to the user.
References:
https://www.salesforcetutorial.com/different-visualforce-controllers/
https://help.salesforce.com/s/articleView?language=en_US&id=sf.pages_merge_fields.htm&type=5







