SObject row was retrieved via SOQL without querying the requested field on managed package

There's a glitch with Visualforce pages regarding namespaces. The workaround is to always use a Visualforce input or output element.

<!-- this is bad -->
{!Account.PackagedField__c}

<!-- this is good -->
<apex:outputField value="{!Account.PackagedField__c}" />

After installing the package in another org, you'll see that salesforce magically patches the reference:

<!-- after installation, in installed org -->
<apex:outputField value="{!Account.namespace__PackagedField__c}" />

I uncovered this glitch on a project I was working for between 2012 and early this year. As far as I know, it's still not listed on Known Issues, nor does there appear to be timeline to fix this glitch. Note also that it doesn't "always" happen, but you should nevertheless always use this design pattern to avoid the problem.

Edit: Also, I recall that this problem would occasionally cause the managed package upload to fail and/or the install to fail with nothing more than a generic Internal Server Error with the usual numbered error code.


I have suffered this error in the past as well, and we followed the same approach as sfdcfox.

In our Visualforce pages, we added a list of outputfields linked to the related sObject fields, and set rendered attribute to false to avoid displaying them:

<apex:outputField value="{!MyCustomObject__c.MyCustomField__c}" rendered="false"/>