Visualforce Page Fundamentals
Visualforce Page Fundamentals are essential knowledge for the Salesforce Certified Platform Developer I exam. Visualforce is a framework that allows developers to build custom user interfaces hosted natively on the Salesforce platform. Here are the key fundamentals: **Basic Structure:** Every Visu… Visualforce Page Fundamentals are essential knowledge for the Salesforce Certified Platform Developer I exam. Visualforce is a framework that allows developers to build custom user interfaces hosted natively on the Salesforce platform. Here are the key fundamentals: **Basic Structure:** Every Visualforce page begins with the `<apex:page>` tag, which serves as the root component. Pages are stored as metadata in Salesforce and can be accessed via unique URLs following the pattern: `/apex/PageName`. **Standard Controllers:** Visualforce pages can leverage standard controllers by specifying `standardController` attribute on the `<apex:page>` tag. This provides automatic access to standard CRUD operations, record data, and navigation without writing Apex code. For example: `<apex:page standardController="Account">` gives access to Account record data. **Custom Controllers & Extensions:** Developers can create custom Apex controllers for complex logic using the `controller` attribute, or extend standard controllers using the `extensions` attribute. Extensions allow you to add custom functionality while retaining standard controller features. **Expression Syntax:** Visualforce uses merge expressions with the syntax `{! expression }` to dynamically reference data, perform calculations, and access controller properties. Global variables like `$User`, `$Label`, and `$Resource` provide access to platform data. **Component Library:** Visualforce offers a rich library of built-in components such as `<apex:form>`, `<apex:inputField>`, `<apex:outputField>`, `<apex:pageBlock>`, `<apex:commandButton>`, and `<apex:dataTable>` that handle rendering, data binding, and user interaction. **View State:** Visualforce maintains view state to preserve page data across server requests in forms. Developers should manage view state carefully to stay within the 170KB limit. **Static Resources:** External files like JavaScript, CSS, and images can be uploaded as static resources and referenced using `$Resource` global variable. **Data Binding:** Visualforce supports automatic data binding between page components and controller properties, enabling seamless two-way communication between the UI and server-side logic. Understanding these fundamentals enables developers to create powerful, custom interfaces that integrate seamlessly with the Salesforce platform.
Visualforce Page Fundamentals – Complete Guide for Salesforce Platform Developer 1 Exam
Why Visualforce Page Fundamentals Matter
Visualforce is a foundational technology on the Salesforce Platform that allows developers to build custom user interfaces. Even though Lightning Web Components (LWC) have become the preferred modern approach, the Platform Developer 1 (PD1) exam still tests your understanding of Visualforce because it remains widely used in production orgs, is essential for maintaining legacy applications, and demonstrates core concepts about how the Salesforce UI framework operates. A solid grasp of Visualforce fundamentals is critical for passing the exam and for real-world Salesforce development.
What Are Visualforce Pages?
Visualforce is a tag-based markup language that allows developers to create custom pages hosted natively on the Salesforce Platform. A Visualforce page is essentially an HTML page enhanced with Salesforce-specific tags (components) that can interact with Salesforce data and logic.
Key characteristics include:
- Tag-based syntax: Visualforce uses XML-like tags prefixed with apex: (e.g., <apex:page>, <apex:form>, <apex:inputField>).
- MVC Architecture: Visualforce pages serve as the View layer. They work alongside Controllers (standard, custom, or extension controllers) which act as the Controller layer, and sObjects and the database represent the Model layer.
- Hosted on Salesforce servers: Pages are stored and served by Salesforce, accessible via unique URLs like /apex/PageName.
- Automatic platform integration: Visualforce natively understands Salesforce metadata, security, and data access controls.
How Visualforce Pages Work
1. Page Structure
Every Visualforce page begins with the <apex:page> tag. This is the root component. Inside it, you place other Visualforce components to build your UI. A minimal page looks like:
<apex:page>
Hello, Visualforce!
</apex:page>
2. Standard Controller
The standard controller is automatically provided by Salesforce for every standard and custom object. When you reference a standard controller on your page (e.g., <apex:page standardController="Account">), you get built-in functionality such as:
- Automatic data retrieval based on the record ID in the URL
- Built-in save, edit, delete, and cancel actions
- Access to the record's fields via merge expressions like {!Account.Name}
3. Custom Controllers
A custom controller is an Apex class that provides all the logic for a Visualforce page. When you use a custom controller (via the controller attribute on <apex:page>), you have full control over data access and page behavior but lose the built-in standard controller functionality. Example: <apex:page controller="MyCustomController">
4. Controller Extensions
Controller extensions let you extend the functionality of a standard or custom controller without replacing it. They are Apex classes that take the standard controller (or custom controller) as a constructor parameter. You reference them with the extensions attribute: <apex:page standardController="Account" extensions="MyExtension">. This allows you to add new methods while retaining standard controller behavior.
5. Expression Syntax (Merge Fields)
Visualforce uses curly-brace expressions {! } to dynamically reference data, call controller methods, and evaluate formulas. Examples:
- {!Account.Name} – displays the Account's Name field
- {!save} – references the save action method
- {!IF(Account.Industry == 'Tech', 'Technology Company', 'Other')} – conditional expression
6. View State
Visualforce maintains state between server requests using the view state. The view state is an encrypted, hidden form field that stores the state of all components on the page. It has a maximum size of 170 KB. Exceeding this limit causes errors. Best practices to reduce view state include using the transient keyword on Apex variables that don't need to persist and minimizing the data stored in controller properties.
7. Key Visualforce Components
- <apex:form> – Required for any input components or action methods that post back to the server.
- <apex:inputField> – Renders the appropriate input widget based on the field's data type and respects field-level security.
- <apex:outputField> – Displays a field value in read-only format, respecting field-level security.
- <apex:commandButton> – A button that invokes a controller action method.
- <apex:commandLink> – A hyperlink that invokes a controller action method.
- <apex:pageBlock> and <apex:pageBlockSection> – Provide Salesforce Classic-styled layout blocks.
- <apex:repeat> – Iterates over a collection to render repeated markup.
- <apex:pageMessages> – Displays error and informational messages added via ApexPages.addMessage().
- <apex:actionFunction> – Provides JavaScript-callable server-side actions.
- <apex:actionSupport> – Adds AJAX behavior to another component (e.g., rerender on change).
8. Data Binding
Visualforce components bind to controller properties using getter and setter methods. If your controller has a property public String myName { get; set; }, the page can reference it as {!myName}. Input components automatically call the setter, and output components call the getter.
9. Partial Page Refresh (AJAX)
Visualforce supports partial page refreshes through the reRender attribute. Instead of refreshing the entire page, you can target specific sections identified by their id attribute. This improves user experience and performance.
10. Visualforce Page Security
- Visualforce pages respect profile-based access: users must have the page enabled on their profile or permission set to access it.
- <apex:inputField> and <apex:outputField> automatically respect field-level security (FLS).
- When using custom controllers, CRUD and FLS are not automatically enforced — developers must explicitly check permissions using methods like Schema.sObjectType.Account.isAccessible().
- Visualforce pages run in system mode when using custom controllers (all object and field permissions are bypassed unless explicitly checked) and in user mode when using standard controllers.
11. Embedding Visualforce Pages
Visualforce pages can be embedded in:
- Page layouts (as inline Visualforce sections)
- Custom tabs
- Custom buttons and links
- Lightning pages (using the Visualforce component in Lightning App Builder, provided the page has Available for Lightning Experience enabled)
12. Governor Limits and Best Practices
- View state limit: 170 KB
- Use the transient keyword to exclude variables from view state
- Minimize SOQL queries in controllers; use efficient queries
- Use <apex:actionRegion> to limit the scope of form submissions
- Avoid deeply nested component hierarchies that increase page processing time
Standard Controller vs. Custom Controller vs. Controller Extension – Summary
Standard Controller: Built-in, provided by the platform for every object. Supports standard CRUD actions. Enforces user permissions automatically. Referenced via standardController attribute.
Custom Controller: An Apex class you write from scratch. Full control over logic. Runs in system mode (no automatic CRUD/FLS enforcement). Referenced via controller attribute. Cannot be used simultaneously with a standard controller on the same page.
Controller Extension: An Apex class that extends a standard or custom controller. Can override or add methods. Constructor accepts a standard controller or custom controller reference. Referenced via extensions attribute. Multiple extensions can be listed (comma-separated), with the first one taking precedence for method resolution.
Exam Tips: Answering Questions on Visualforce Page Fundamentals
1. Know the difference between standard controllers, custom controllers, and extensions. This is one of the most commonly tested areas. Remember: you cannot use both controller and standardController attributes on the same page. Extensions use the extensions attribute alongside either standardController or controller.
2. Understand view state. Know the 170 KB limit, what gets stored in view state, and how the transient keyword prevents data from being included. Questions may ask how to reduce view state size.
3. Remember that custom controllers run in system mode. This means CRUD and FLS are not enforced automatically. If a question asks about security enforcement, the answer for custom controllers is that the developer must explicitly check permissions.
4. Standard controllers run in user mode and automatically enforce sharing rules, CRUD, and FLS. This is a key distinction from custom controllers.
5. Know which components require an <apex:form> tag. Any component that submits data to the server (like <apex:commandButton>, <apex:commandLink>, <apex:inputField>) must be placed inside an <apex:form>. This is a common trick question area.
6. Understand the reRender attribute. It targets a component's id for partial page refresh. Know that it uses AJAX and does not reload the entire page.
7. Be familiar with merge expression syntax. Questions may test whether you can correctly read {!Account.Name}, {!save}, or {!IF(condition, trueValue, falseValue)}.
8. Controller extension constructor signatures matter. For a standard controller extension, the constructor must accept ApexPages.StandardController as a parameter. For extending a custom controller, the constructor accepts the custom controller class type.
9. Multiple extensions precedence. When multiple extensions are listed, the leftmost extension takes precedence. If both extensions define the same method, the one listed first wins.
10. Recognize when to use Visualforce vs. Lightning. The exam may present scenarios where you need to choose the right UI technology. Visualforce is appropriate for Salesforce Classic customizations, PDF generation (using renderAs="pdf"), and pages requiring server-side rendering. Lightning components are preferred for Lightning Experience and mobile.
11. Read questions carefully for keywords. Words like "standard controller," "custom controller," "extension," "system mode," "user mode," "view state," and "transient" are strong clues pointing to specific correct answers.
12. Practice identifying invalid code. The exam may show Visualforce markup with errors (e.g., using both controller and standardController, missing <apex:form>, or incorrect expression syntax) and ask you to find the issue.
13. Remember the renderAs attribute. Setting renderAs="pdf" on <apex:page> renders the page as a PDF document. This is a commonly tested feature.
14. Understand Standard List Controllers. Using recordSetVar on <apex:page> along with a standard controller enables list-based operations, including pagination methods like next(), previous(), first(), and last().
By mastering these fundamentals — the architecture, component model, controller types, security implications, and view state management — you will be well-prepared to answer Visualforce-related questions on the Salesforce Platform Developer 1 exam confidently and accurately.
🎓 Unlock Premium Access
Salesforce Certified Platform Developer I + ALL Certifications
- 🎓 Access to ALL Certifications: Study for any certification on our platform with one subscription
- 2750 Superior-grade Salesforce Certified Platform Developer I practice questions
- Unlimited practice tests across all certifications
- Detailed explanations for every question
- PD1: 5 full exams plus all other certification exams
- 100% Satisfaction Guaranteed: Full refund if unsatisfied
- Risk-Free: 7-day free trial with all premium features!