- Home
- Technical Library
- Boards
- Cookbook
- Code Share
- Blogs
- Partners
-
More
-
Services
- Training & Certification
- Support
-
Galleries
- Force.com Sites Gallery
- Chatter Challenge Entries
-
Other Web Sites
- Salesforce.com
- Database.com
- AppExchange
- CRM Community
-
Discussions
- Announcements
- General Development
- Schema Development
- New to Cloud Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules Discussion
- Security
- Mobile
- Force.com Sites
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby Development
- Adobe Flash Builder for Force.com
- Desktop Integration
- REST API Integration
- Streaming API
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- Excel Connector
- AJAX Toolkit & S-controls
- Force.com Builder & Native Apps
- AppExchange Directory & Packaging
- Force.com Labs Projects
- Open Source
- Site.com
- Jobs Board - Administrators
- Jobs Board - Developers
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Visualforce Development
- :
- error referencing field, using standard controller...
turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
error referencin g field, using standard controller extension
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-24-2008 05:24 PM
I've got a VF page & controller extension for a custom obj., and I've set it to be the override for the Edit action for the obj.
Here's simplified versions of the code.
Page:
and controller:
The problem is that when I attempt to edit a Condition record, VF gives me the following error:
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Criterion__c
The line cited is:
string critID = this.cond.Criterion__c;
I don't understand this error. Since I'm starting from an existing record, doesn't this line:
this.cond = (Condition__c)stdController.getRecord();
load in the record in its entirety? Why would one or more fields be left out?
BTW, Condition__c is a master-detail relationship field. So I know that there's data in the field for the record I want to edit.
Thanks for any help!
PS This code works fine when I use the same page to add a new Condition record, instead of editing an existing one. That's where the 'cr' querystring param comes in. I pass that in to indicate the id that should be put into the Criterion__c field. That works fine, but not when attempting to edit an existing record.
Here's simplified versions of the code.
Page:
Code:
<apex:page standardController="Condition__c" extensions="NNRG_CNT_Condition" tabStyle="Assessment__c">
<apex:form >
<apex:pageblock title="Condition Edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageblockSection columns="1" title="Condition" collapsible="false">
<apex:pageblockSectionItem >
<apex:outputLabel value="Assessment" />
<apex:outputText value="{!asName}" />
</apex:pageblockSectionItem>
<apex:pageblockSectionItem >
<apex:outputLabel value="Criterion" />
<apex:outputText value="{!critNbr} ({!critTxt})" />
</apex:pageblockSectionItem>
<apex:inputField value="{!Condition__c.Condition_Text__c}" />
<apex:inputField value="{!Condition__c.Pre_Condition__c}" />
</apex:pageblockSection>
</apex:pageblock>
</apex:form>
</apex:page>and controller:
Code:
public class NNRG_CNT_Condition {
private final Condition__c cond;
public string asName {get;set;}
public string critNbr {get;set;}
public string critTxt {get;set;}
// constructor
public NNRG_CNT_Condition (ApexPages.StandardController stdController) {
this.cond = (Condition__c)stdController.getRecord();
if ( this.cond.Id == null ) {
this.cond.Criterion__c = System.currentPageReference().getParameters().get( 'cr');
}
string critID = this.cond.Criterion__c;
Criterion__c crit = [SELECT Id, Name, Short_Text__c, Assessment__r.Name, Criterion_Number__c FROM Criterion__c
WHERE Id=:critID LIMIT 1];
asName = crit.Assessment__r.Name;
critNbr = crit.Criterion_Number__c;
critTxt = crit.Short_Text__c;
}
}The problem is that when I attempt to edit a Condition record, VF gives me the following error:
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Criterion__c
The line cited is:
string critID = this.cond.Criterion__c;
I don't understand this error. Since I'm starting from an existing record, doesn't this line:
this.cond = (Condition__c)stdController.getRecord();
load in the record in its entirety? Why would one or more fields be left out?
BTW, Condition__c is a master-detail relationship field. So I know that there's data in the field for the record I want to edit.
Thanks for any help!
PS This code works fine when I use the same page to add a new Condition record, instead of editing an existing one. That's where the 'cr' querystring param comes in. I pass that in to indicate the id that should be put into the Criterion__c field. That works fine, but not when attempting to edit an existing record.
Solved! Go to Solution.
Re: error referencin g field, using standard controller extension
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-24-2008 08:22 PM
sparky wrote:
I don't understand this error. Since I'm starting from an existing record, doesn't this line:
this.cond = (Condition__c)stdController.getRecord();
load in the record in its entirety? Why would one or more fields be left out?
No. You are getting the record from the standard controller, and the standard controller automatically constructs your SOQL query for you based on the fields that are referenced in your page. It would not make sense performance-wise for us to load up every single field on your object if all you want to reference is a couple of fields.
So to get around this you can either do another query for your field in your controller (not recommended), or better yet you can simply include a hidden reference to it on your page somewhere, something like:
Code:
<apex:outputText value="{!Condition__c.Criterion__c}" rendered="false"/>The standard controller will pick it up when constructing your query and you will be free to reference it in your extension.
Re: error referencin g field, using standard controller extension
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-25-2008 12:16 PM
Thanks, Jill! That seems like a very important concept, that I somehow completely missed. It certainly makes sense from a resource-optimization standpoint, but it's not exactly intuitive.
Just out of curiosity, is this noted in the docs anywhere? I never saw it, but could easily have missed it.
Just out of curiosity, is this noted in the docs anywhere? I never saw it, but could easily have missed it.
Re: error referencin g field, using standard controller extension
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
07-25-2008 12:24 PM
I think it's something you could infer from the standard controller doc but it's not completely clear. My doc writer just asked me the exact same question a couple days ago :) I'll see if we can add something.

