Print this page

Getting error "SObject row was retrieved via SOQL without querying the requested field" in managed code in subscriber org but not in developer org

Knowledge Article Number 000187683
Description - A Visualforce page is part of a managed package
- It contains a component whose attribute value references managed objects and fields
- The attribute value also has a line break
- For example:

<apex:outputPanel layout="none" rendered="{!( !ISBLANK(Object__c.ParentObject__r.CustomField1__c)
                                        && Object__c.ParentObject__r.CustomField1__c < Object__c.CustomField3__c)">
    Panel text
 </apex:outputPanel>


- In the developer org, this code is okay because namespaces are not used for object and field references.
- In a subscriber org (an org that has installed the managed code), the Visualforce markup should look like:

<apex:outputPanel layout="none" rendered="{!( !ISBLANK(Namespace__Object__c.ParentObject__r.Namespace__CustomField1__c)
                                        && Namespace__Object__c.Namespace__CustomField1__c < Object__c.Namespace__CustomField3__c)">
    Panel text
 </apex:outputPanel>


i.e. managed objects and fields are prefixed with the packages namespace.

- Line breaks in attribute values disrupt the evaluation of those values.  For example:

<apex:outputPanel rendered="tr
                                                          ue">
Hello
</apex:outputPanel>


does not render, because the value is not handled by our parser.

- The line break in the value passed to the rendered attribute of <apex:outputPanel> in the first example above, our parser does not asses it correctly and does not insert the Namespace__ in the code.
- Remember that the Namespace__ is only inserted into the code on package install.  It can be viewed or verified via Blacktab.
- As a result, the markup for the rendered attribute's value does not contain the correct namespace.
- When the page is rendered, the standard controller attempts to reference this object and its fields without the namespace.
- Because those objects and fields do not exist in the subscriber org's namespace, we receive the error:  "SObject row was retrieved via SOQL without querying the requested field"
Resolution - Reduce the rendered attribute value to a single line;  remove all line breaks.

<apex:outputPanel layout="none" rendered="{!( !ISBLANK(Namespace__Object__c.ParentObject__r.Namespace__CustomField1__c) && Namespace__Object__c.Namespace__CustomField1__c < Object__c.Namespace__CustomField3__c)">
    Panel text
 </apex:outputPanel>




promote demote