[SalesForce] Error message: SObject row was retrieved via SOQL without querying the requested field

I receive the following error:

SObject row was retrieved via SOQL without querying the requested field: Installation__c.Name 

Controller extension on custom object:

public class CrewWorkDetailController{

    public final Installation__c installation {get; private set;}

    public CrewWorkDetailController(ApexPages.StandardController stdController)
    {
        this.installation = (Installation__c) stdController.getRecord() ;
    }
}

View:

<apex:page standardController="Installation__c" extensions="CrewWorkDetailController">
    {!installation.Name}
</apex:page>

This is based on this example. Any ideas?

I tried renaming my variable and still does not work.

Best Answer

The only fields that are queried by default are the fields that are explicitly bound to the main standard controller during the page's construction (before the constructor of your extension is called).

You have two choices here:

1) You can use StandardController.reset() and StandardController.addFields() to add Name as a field to query.

2) You can bind directly the standard controller's record by using the name of the object:

<apex:page standardController="Installation__c" extensions="CrewWorkDetailController">
    {!installation__c.Name}
</apex:page>