Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I recieve 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.

share|improve this question
    
Try calling your variable something besides installation. –  greenstork Jun 12 at 15:59
    
I tried renaming my variable and still does not work. –  Daniel Jun 12 at 16:08
1  
How are you testing this page that it's not working. Have you overrode the standard New or View for your custom object with your extension. A controller extension relies on a standard object controller to be passed into it. Just viewing an apex page for an extension could also lead to your error. –  greenstork Jun 12 at 16:17
    
@greenstork The code I put in the question is all I have. I clicked preview and appended id of installation to url. The answer provided by sfdcfox seems to be right. Thanks for your help. –  Daniel Jun 12 at 16:25

1 Answer 1

up vote 5 down vote accepted

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>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.