+ Start a Discussion
dwwrightdwwright 

Visualforce Error: SObject row was retrieved via SOQL without querying the requested field

I'm receiving this error on a very large (5000+ lines) VisualForce page that is used to display forms for users to fill out. The page supports several different forms, and displays whichever form is necessary based on the name of the form to be displayed (name of the form object record).

 

I have well over 100 fields from the object on this page. I added a few more fields today, and when I try to display them in an inputField component, I'm suddenly getting the:  SObject row was retrieved via SOQL without querying the requested field error. I tried putting the field at the top of the page as an <apex:inputhidden> component, and also as an <apex:outputtext rendered="false> component as referenced in this thread:

 

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=19680

 

 Still, I'm getting the error message.  If I put this field on another visualforce page (much smaller with only 1 or 2 fields) it displays with no problem. is there some kind of limit to how many fields from an object are queried by the Standard Controller? If anyone knows what may be going on here, please let me know. A snippet from my page is below:

 

<apex:page id="SDQA" standardController="SDQA__c" extensions="NewSDQAExtension" showHeader="false"> <apex:form> <apex:inputHidden value="{!SDQA__c.OperatorStamp45__c}" /> ...Lots and lots of code.... <apex:inputField value="{!SDQA__c.OperatorStamp45__c}" required="true" /> </apex:form> </apex:page>

 

 

 

 

 

SteveBowerSteveBower

Did you add any of these fields to columns in a repeat block or some construct where the data is being loaded by some code in your Controller extension?

 

You are correct that using the inputField should make the standard controller load those fields correctly.  However, I presume that you have an extension for a reason, and perhaps you're loading data in there somewhere and you need to add the columns to a query you're executing directly?

 

 

If you look at the debug log do you get any better information?

 

Best, -S

dwwrightdwwright

I don't do any querying of my own in the extension. It's purpose is to make changes to some of the fields on the object before inserting it, and to control where the user is directed to after DML operations (as I'm passing my users to various visualforce pages). The construcor for my extension:

 

 

public class NewSDQAExtension {

private SDQA__c S;

//constructor
public NewSDQAExtension(ApexPages.StandardController theController) {
this.S = (SDQA__c)theController.getRecord();
}

 

 So as you can see, I'm simply making changes directly to the record from the standardController. The field I'm having trouble with is not in any kind of repeat or pageblocktable column. I have a series of outputpanels with the rendered attribute set so that the appropriate panel will display based on the name of the SDQA__c record (this allows me to display multiple different forms using the same object with generic fields) This error ONLY occurs when the outputpanel containing this field is rendered...

 

Chris987654321Chris987654321
But does it give you this error if you just have 1 rendered field or if you render a bunch? What if you comment out everything except 1 rendered field?
SteveBowerSteveBower

Hi, from what you're saying, and what you've posted it seems that everything should be working.  Just to be clean, I might change the <apex:inputHidden> tag to an outputField tag with rendered="false", or perhaps even just remove it.   (I'd think that the one inputField tag should be sufficient, but perhaps not...)

 

Perhaps post all the code (Not that I really want to see a 5000+ line VF page)!

 

Otherwise, start stripping out the other panels, get rid of the rendered conditional on this one, and keep trimming until you get down to something that does work and then back things in.

 

Best, Steve.

 

p.s. What datatype is the field? 

dwwrightdwwright

Steve,

 

The data type of the field is Text. I've actually been able to work around the problem. The control flow of the pages when I was having the error was: 

 

User clicks on a child record from the related list on the master object's view page ----> User directed to an override page for editing the child object record ----> User clicks on a button that sends them to a confirmation page for that object (/apex/myPage?id=xxxxxxxxxxxxxx) ---> Confirmation page displays the error

 

What I did was first display the fields on the edit override page before directing them to the confirmation page. The fields are then queried with no problem. Strange, and I still don't think I was doing anything wrong... 

SteveBowerSteveBower

Well, I'm glad you've got it working, but yes, that seems very strange to me.

 

In theory, if you navigate to the  /apex/vfpage?id=xxxxx manually, just by typing in the url, you should still get proper behavior and it sounds like you wouldn't.

 

Either way, a workaround is a workaround... moving onwards!  :-)  Best, Steve.