Documentation Version
Winter '16 (API version 35.0)
  • Winter '16 (API version 35.0) 35.0
  • Summer '15 (API version 34.0) 34.0
  • Spring '15 (API version 33.0) 33.0
  • Winter '15 (API version 32.0) 32.0
  • Summer '14 (API version 31.0) 31.0
  • Spring '14 (API version 30.0) 30.0
  • Winter '14 (API version 29.0) 29.0
  • English

Overriding an Existing Page with a Visualforce Page

Suppose you want to change the format of an existing page, such as the standard account detail page. All the information for an account displays on a single page. If there's a lot of information, you might end up doing a lot of scrolling. Using a Visualforce page you can make each section for an account display in a tab, such as contacts, opportunities, and so on.

First, create a new Visualforce page using the quick fix.

  1. In your browser, add the text /apex/tabbedAccount to the URL for your Salesforce instance. For example, if your Salesforce instance is, the new URL would be You will get the following error message:
    A Visualforce error stating "Page tabbedAccount does not exist"
  2. Click Create Page tabbedAccount to create the new page.
  3. Click the Page Editor link in the bottom left corner of the page. This displays the code for the new page, which should look like this:
    <!-- Begin Default Content REMOVE THIS --> 
    This is your new Page: tabbedAccount 
    <!-- End Default Content REMOVE THIS --> 
  4. Replace the existing code with the following and click Save:
    <apex:page standardController="Account" showHeader="true" 
          tabStyle="account" >
          .activeTab {background-color: #236FBD; color:white; 
          .inactiveTab { background-color: lightgrey; color:black; 
       <apex:tabPanel switchType="client" selectedTab="tabdetails" 
                      id="AccountTabPanel" tabClass='activeTab' 
          <apex:tab label="Details" name="AccDetails" id="tabdetails">
             <apex:detail relatedList="false" title="true"/>
          <apex:tab label="Contacts" name="Contacts" id="tabContact">
             <apex:relatedList subject="{!account}" list="contacts" />
          <apex:tab label="Opportunities" name="Opportunities" 
             <apex:relatedList subject="{!account}" 
                               list="opportunities" />
          <apex:tab label="Open Activities" name="OpenActivities" 
             <apex:relatedList subject="{!account}" 
                               list="OpenActivities" />
          <apex:tab label="Notes and Attachments" 
                    name="NotesAndAttachments" id="tabNoteAtt">
             <apex:relatedList subject="{!account}" 
                               list="CombinedAttachments" />
  5. Notice that there is no data in the Account page. You need to specify the ID of a particular account in the URL, as you've done with previous pages, for example, https://Salesforce_instance/apex/tabbedAccount?id=001D000000IRt53. After you add in an account ID, your page should display as follows:
    The Visualforce Page Editor, displaying an account detail page

Things to note about the page markup:

  • <style> is actually part of CSS markup, not Visualforce markup. It defines the styles for two types of tabs: activeTab and inactiveTab.
  • <apex:tabPanel> is used to generate the tabs. Notice how it uses the following attributes:
    • tabClass attribute: specifies the style class used to display a tab when it is active.
    • inactiveTabClass attribute: specifies the style class used to display a tab when it is inactive.
  • Within the definition of the tab panel, is the definition of each child tab component, <apex:tab>. The first tab uses the <apex:detail> tag to return that portion of the detail view for the page:
          <apex:tab label="Details" name="AccDetails" id="tabdetails">
             <apex:detail relatedList="false" title="true"/>
    While the rest of the tabs use the <apex:relatedList> to specify the different parts of the account page. The following is the tab for contacts. It uses an existing list of contacts.
          <apex:tab label="Contacts" name="Contacts" id="tabContact">
             <apex:relatedList subject="{!account}" list="contacts" />
Now that you've created a page to display an account with tabs, you can use this page to override the detail view for all accounts.
  1. From the object management settings for accounts, go to Buttons, Links, and Actions.
  2. Click Edit next to View.
  3. For Override With select Visualforce Page.
  4. From the Visualforce Page drop-down list, select tabbedAccount.
  5. Click Save.

Click the Account tab, and select any account. The detail for the account is now displayed with tabs.