The <apex:page>
component is the foundation of every Visualforce page. It’s the root tag that defines a Visualforce page and controls key aspects like layout, controller reference, and page behavior.
Syntax
xmlCopyEdit<apex:page>
<!-- Page content goes here -->
</apex:page>
Common Attributes
Attribute | Description |
---|---|
controller | Specifies a custom Apex controller |
recordSetVar | Used for list controllers |
standardController | Ties the page to a Salesforce standard object like Account , Contact |
showHeader | Shows/hides Salesforce standard header (true /false ) |
sidebar | Shows/hides sidebar (true /false ) |
title | Custom title for the page |
Example 1: Basic Page
xmlCopyEdit<apex:page>
<h1>Welcome to Salesforce Visualforce!</h1>
</apex:page>
Example 2: With Standard Controller
xmlCopyEdit<apex:page standardController="Account">
<h1>Account Name: {!Account.Name}</h1>
</apex:page>
Example 3: With Custom Controller
xmlCopyEdit<apex:page controller="MyController">
<h1>Hello, {!name}</h1>
</apex:page>
When to Use <apex:page>
- Always – It’s the container for all other Visualforce components.
- It defines how the page connects with Apex logic or standard Salesforce records.
Best Practices
- Always set
showHeader="false"
andsidebar="false"
for public/embedded pages. - Use
title
to help with page SEO and browser tabs. - Minimize logic in the page — keep business logic in controllers.