How to use Account Object in custom page controller ?

I did the following steps :

  1. I create a New Tab for Visualforce Page

setup-->app setup--> create-->tabs clicked "New" under visualforce tab and entered details and choose the visualforce pages which i have already created. And clicked next and choose the application in which i want that tab to be included and clicked save.

  1. Extend the Account - StandardController like that: http://www.salesforce.com/us/developer/docs/pages/Content/apex_pages_standardcontroller.htm

  2. Setup the tabstyle - Attribute like the example-link like that: https://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std_styling.htm

My VF-Page will be init like:

<apex:page standardController="Account" extensions="OrderController" tabStyle="Order__tab">

My OrderController will be init like:

public with sharing class OrderController {

private final Account account; 
public OrderController(ApexPages.StandardController controller) {   
      this.account = (Account)controller.getRecord();

    //1.) does not work because there is no id url-parameter in url
    //account = [SELECT Id, Name, Owner.FirstName FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('Id')];

    if(this.account == null){
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'account = null'));
   //2.) all properties of the account Object are still NULL
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'account.id: ' + this.account.Id));
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'account.name: ' + this.account.name));
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'account.Owner: ' + this.account.Owner.FirstName));

The result of it is that the properties of this.account like id, name, Owner are null

Why ? I need the properties of this.account to create a valid order.

  • How you are calling this VF page? From a button on Account detail page or from some tab or directly in URL?
    – Aditi Jain
    Oct 8, 2014 at 13:15
  • from some tab. in the main pane, near: ...| Reports | Dashboards | Getting Started | MyOrderTab | +
    – blub
    Oct 8, 2014 at 13:21
  • 1
    So it means there is no account Id in URL that is why this.account is null.
    – Aditi Jain
    Oct 8, 2014 at 13:32
  • And how can i fix that ? I need the account object in my custom page / controller
    – blub
    Oct 8, 2014 at 13:35

2 Answers 2


Create a new custom button(preferable a detail page button) on an Account object, add your custom VF page in source and add on page layout.

Because to have an Account via getRecord() method in constructor, you must give the account Id either directly in the URL or use a button as I mentioned above.


It depends on what you want to achieve.

The approach you are using via standard controller and extensions is good to override e.g. the account view / edit pages. If you do so in the setup, you'll get your id-param populated by the platform. If this is what you want, have a look here: https://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_tabs.htm

But you right now, you seem to be using it out-of-context, likely in an uncoupled custom tab. There you have no id-param. So either you have to provide it on your own (e.g. via a link or button) or - if you want to relate this some how to an "Order" (which could be indicated by your tabStyle selection) you can query the order (we don't now if you use custom or standard) and probably get a relation to an account there, too.

  • What i want to achieve is in short: 1. load a existing report based on Contact-Fields; 2. create a Orderlist from the report-result. Each OrderItem from the Orderlist is filled with content of the Contact-Fields and some Account-Fields.
    – blub
    Oct 8, 2014 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .