You need to sign in to do that
Don't have an account?
Despite calling addFields method, I get "SObject row was retrieved via SOQL without querying the requested field" error
Hi everyone,
I've a VF page with standard controller and an extension. In an action invoked by a postback request, I add one new field into the standard controller (Using reset() & addField() methods ) and then refer that new field dynamically onto the page as it rerenders. When the page rerenders after this postback, I get follwoing error:
SObject row was retrieved via SOQL without querying the requested field: Account.Name
Here "Name" is the new field that I add into the action method. The error suggest that I didnt understand the concept of reset() and addFields() correctly and may be using in wrong manner.
Please help me resolve this error and explain the use/purpose & right sequence of these two methods.
I've a VF page with standard controller and an extension. In an action invoked by a postback request, I add one new field into the standard controller (Using reset() & addField() methods ) and then refer that new field dynamically onto the page as it rerenders. When the page rerenders after this postback, I get follwoing error:
SObject row was retrieved via SOQL without querying the requested field: Account.Name
Here "Name" is the new field that I add into the action method. The error suggest that I didnt understand the concept of reset() and addFields() correctly and may be using in wrong manner.
Please help me resolve this error and explain the use/purpose & right sequence of these two methods.
It's not ideal but definitely a viable work around.
Thx
All Answers
Have you used SOQL Query anywhere in your code, check if it is having Name field queried. If this also doesn't solves your issue please paste your code, else it will be difficult to resolve your issue.
Please let me know if this helps.
Thanks and Regards,
Anirudh Singh
Here I do not access any queried record, rather I access the record supplied by standard controller.
Ok, I'm posting my page & controlle, this will assit in help.
Apex , VisualForce
Last updated 2015-06-30 ·Reference W-1571056 ·Reported By 16 users
No Fix
Summary
When using StandardController.reset() with dynamic visualforce, the error "SObject row was retrieved via SOQL without querying the requested field" can be thrown
more info:
https://success.salesforce.com/issues_view?id=a1p30000000Sw8tAAC
Workaround
A workaround for now could be to statically declare fields that might be included, but don't render them:
<apex:outputText value="{!myObject__c.field__c}" rendered="false"/>
OR
<apex:inputhidden value="{!myObject__c.field__c}" />
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks
After debugging this error, I found the methods reset & addFields dont thorw any exception. The error comes when we try to access the field which was not added from the beginning, may be because reset & addFields are not doing thier work as expected.
As suggested, referencing fields in the markup could be a good workaround for this, but I fear, it will not work in case we dont know the fields beforehand or if it depends on user input.
It's not ideal but definitely a viable work around.
Thx