function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Elizabeth StelterElizabeth Stelter 

Issues with SOQL queries with packages and namespaces

I am having issues where writing a VF page one way will work in the instance I am developing a managed package in, but not the one I install it in, or vice versa (which is even weirder to me).  Both are developer editions, and I haven't set up an environment hub (although it is on my to-do list).  Basically, if I put in the namespace prefix, it won't work in the instance I am building it in, but if I don't include the namespace prefix it won't work when I install it in a different instance.  

I feel like there must be a way for it to work in both, but I am using this project to teach myself as I go and feel like I must have missed something along the way.  

The following (condensed version) works in the development instance but throws the following error in the installed instance. 
"SObject row was retrieved via SOQL without querying the requested field: pattersonrd__NPBPCL__c.Name"  
<apex:page standardController="pattersonrd__NPBPCL__c" tabStyle="pattersonrd__NPBPCL__c">
    <apex:form >
        <apex:sectionheader title="Checklist Edit" subtitle="{! IF(NPBPCL__c.Id==null,'New Checklist',NPBPCL__c.Name)}"></apex:sectionheader>
        <apex:pageblock mode="edit" id="checklistPB" title="Checklist Edit">

            <apex:pageblockbuttons >
                <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
                <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
            </apex:pageblockbuttons>

            <apex:pagemessages ></apex:pagemessages> 
            		
            <apex:pageBlockSection title="Version" id="VersionPBS">
                <apex:inputField value="{! NPBPCL__c.Name }"/>
                    Name this checklist after the period under review, such as "2015 Checklist" or "3rd Quarter 2017 Checklist."  Conducting regluar reviews will help you track your progress over time.
            </apex:pageBlockSection>
            
            <apex:pageBlockSection Title="Federal" id="FederalPBS" columns="1">        
                <apex:pageBlockSection Title="Nonprofit Status" id="NonprofitStatusPBS">
                    <apex:inputField value="{! NPBPCL__c.Obtain_501_c_3_Status__c }" />
                    Obtaining your 501(c)3 status can be a long process, typically taking 2-12 months.
                    <apex:inputField value="{! NPBPCL__c.Retain_Determination_Letter__c }" />
                    You will need this document to prove your status to grantors and others.
</it goes on with input fields for quite a while and then has all the proper closing tags. but all the input fields are in the same basic format>

The following (condensed version) works in the installation instance but throws the following error in the development instance. 
"System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: pattersonrd__NPBPCL__c.Name "
<apex:page standardController="pattersonrd__NPBPCL__c" tabStyle="pattersonrd__NPBPCL__c">
    <apex:form >
        <apex:sectionheader title="Checklist Edit" subtitle="{! IF(pattersonrd__NPBPCL__c.Id==null,'New Checklist',pattersonrd__NPBPCL__c.Name)}"></apex:sectionheader>

        <apex:pageblock mode="edit" id="checklistPB" title="Checklist Edit">

            <apex:pageblockbuttons >
                <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
                <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
            </apex:pageblockbuttons>
            
            <apex:pagemessages ></apex:pagemessages> 
            
            <apex:pageBlockSection title="Version" id="VersionPBS">
                <apex:inputField value="{! pattersonrd__NPBPCL__c.Name }"/>
                    Name this checklist after the period under review, such as "2015 Checklist" or "3rd Quarter 2017 Checklist."  Conducting regluar reviews will help you track your progress over time.
            </apex:pageBlockSection>
            
            <apex:pageBlockSection Title="Federal" id="FederalPBS" columns="1">        
                <apex:pageBlockSection Title="Nonprofit Status" id="NonprofitStatusPBS">
                    <apex:inputField value="{! pattersonrd__NPBPCL__c.pattersonrd__Obtain_501_c_3_Status__c }" />
                    Obtaining your 501(c)3 status can be a long process, typically taking 2-12 months. 
                    <apex:inputField value="{! pattersonrd__NPBPCL__c.pattersonrd__Retain_Determination_Letter__c }" />
                    You will need this document to prove your status to grantors and others.
</it goes on with input fields for quite a while and then has all the proper closing tags.  but all the input fields are in the same basic format>

 
LBKLBK
Hi Elizabeth,

You need to setup Namespace for the ORG where you develop the application.

That is the only way to make it work with Namespace.

Once you build the package (with namespace), it will work on any destination ORGs.
Elizabeth StelterElizabeth Stelter
Thank you for the info.  "pattersonrd" is the namespace listed on both the package details and under my developer settings on the packages setup page.  Is there somewhere else I need to add it?
LBKLBK
No. Package setup page is the only place.

Once you add the namespace (pattersonrd), all your custom objects, fields, classes, etc. will have their name begin with pattersonrd__.

That is what you have to refer in the destination ORGs (post deployment of managed package).
Elizabeth StelterElizabeth Stelter
The API names for the custom objects and fields, as listed on the object setup page for both orgs, all include "pattersonrd__" as a prefix.