1

I have a VF page that works fine in a Dev org, but when installed in another org it breaks with: SObject row was retrieved via SOQL without querying the requested field: Namespace__Hub__c.Namespace__ClientName__c

<apex:page standardController="Hub__c" extensions="HubControllerExtension">
    <apex:form >
        <apex:pageBlock title="Hub">
            <apex:pageBlockSection columns="1">
                <apex:pageMessages />
                <apex:inputField value="{! Hub__c.ClientName__c }"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{! save }" value="Save" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

When I look at the VF code that's installed in the new org, the only difference is the first line:

<apex:page standardController="Hub__c" extensions="HubControllerExtension">

is now:

<apex:page standardController="Namespace__Hub__c" extensions="Namespace.HubControllerExtension">

It seems that the actual input field is still <apex:inputField value="{! Hub__c.ClientName__c }"/> and not <apex:inputField value="{! Namespace__Hub__c.ClientName__c }"/> which looks wrong to me.

If I copy the HubControllerExtension class into a new class in the new org, and create a new VF page that prepends the Namespace to the fields, everything works:

<apex:page standardController="Namespace__Hub__c" extensions="HubControllerExtensionTwo">
    <apex:form >
        <apex:pageBlock title="Hub">
            <apex:pageBlockSection columns="1">
                <apex:pageMessages />
                <apex:inputField value="{! Namespace__Hub__c.Namespace__ClientName__c }"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{! save }" value="Save" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

However, if I try to prepend the namespace in the input field in the Dev org, it fails in the Dev org.

I was under the impression that a managed package would automatically prepend the namespace when installed in another org. What am I doing wrong?

0

Ok I solved it. I had to manually use the addFields method in the controller extension to add all the fields needed.

public HubControllerExtension(ApexPages.StandardController stdController) {
    List<String> fields = new List<String> { 
        'Namespace__ClientName__c',
         ...
    };
    if (!Test.isRunningTest()) {
         stdController.addFields(fields);
    }
    this.hub = (Namespace__Hub__c)stdController.getRecord();
}

Not sure why this was required, but it works!

The addFields documentation states that:

When a Visualforce page is loaded, the fields accessible to the page are based on the fields referenced in the Visualforce markup.

So you would think that this wouldn't be necessary, but that is not the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.