+ Start a Discussion
econtractorproecontractorpro 

Apex Error: SObject row was retrieved via SOQL without querying the requested field:

SUMMARY
I have signed up for the Salesforce Partner Program and have created a managed app called ABC Company using my Partner Developer Edition account (dev org).

The app consists of one parent custom object (Project__c) and two child custom objects (Sent_item__c & Received_item__c).

I have a visualforce PDF page that displays the Project Summary with the Sent and Received related lists. For this VF PDF Page I have created an Apex Class that sorts/orders the list by Name ASC for Sent and Received Related Lists. I also have an apex test class with 100% code coverage.

The Generate Visualforce PDF Page works without any problems in my Partner Developer Edition account (dev org).

PROBLEM
After successful installation of my app on my Enterprise/Platform Edition account (Test Org) as a managed app I receive the following error when I try to generate the VF page:

common.apex.runtime.impl.ExecutionException: SObject row was retrieved via SOQL without querying the requested field:ecpfinal__Project__c.Name

(The error only occurs in my managed solution when installed on another Enterprise/Platform Edition account (Test Org))

Can you provide the necessary code to fix this error? Do I need to add additional code to the apex class?

VISUALFORCE PDF PAGE (Project_Summary)
<apex:page standardController="Project__c" sidebar="false" showHeader="false" renderAs="pdf" extensions="ProjectSummaryPDFController">
<hr></hr>
   <h3>PROJECT SUMMARY</h3>
<hr></hr>
 <table  style="width: 100%;">
<tr><td style="width: 25%;">Project Number:</td><td style="width: 75%;">{!Project__c.Name}</td></tr>
<tr><td style="width: 25%;">Project Name:</td><td style="width: 75%;">{!Project__c.Project_Name__c}</td></tr>
<tr><td style="width: 25%;">Contractor:</td><td style="width: 75%;">{!Project__c.Contractor__c}</td></tr>
 </table>
 <hr></hr>
   <b>SENT ITEMS</b>
<hr></hr>
<apex:dataTable value="{!cvSentItemLineItemsSorted}" var="item" border="1" cellpadding="3" width="100%" >
<apex:column >
<apex:facet name="header">Item Number</apex:facet>
<apex:outputText value="{!item.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Description</apex:facet>
<apex:outputText value="{!item.Description__c}"/>
</apex:column>
 </apex:datatable>
<hr></hr>
   <b>RECIEVED ITEMS</b>
<hr></hr>
 <apex:dataTable value="{!cvReceivedItemLineItemsSorted}" var="item" border="1" cellpadding="3" width="100%" >
<apex:column >
<apex:facet name="header">Item Number</apex:facet>
<apex:outputText value="{!item.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Description</apex:facet>
<apex:outputText value="{!item.Description__c}"/>
</apex:column>
 </apex:datatable>
  <hr></hr>
</apex:page>


APEX CLASS
public with sharing class ProjectSummaryPDFController {
       //set up the class variables we'll need to reference from VF page
       public List<Sent_item__c> cvSentItemLineItemsSorted {public get; private set;}
       public List<Received_item__c> cvReceivedItemLineItemsSorted {public get; private set;}
       
       //variable to hold current Project__c record
       private Project__c cvSelectedProject = null;
       
       //constructor
       public ProjectSummaryPDFController(ApexPages.StandardController pCntrllr)
       {
               // grab current Project__c record from the Standard Controller
               cvSelectedProject = (Project__c)pCntrllr.getRecord(); 
                       
               // build sorted List of Sent_item__c records for current Project__c
               cvSentItemLineItemsSorted = new List<Sent_item__c>();
               cvSentitemLineItemsSorted = 
                       [Select item.Name,
                               item.Description__c
                        From Sent_item__c item
                        Where item.Project_Number__c =: cvSelectedProject.id
                        ORDER BY item.Name ASC
                        limit 1000];
               
               // build sorted List of Received_item__c records for current Project__c
               cvReceivedItemLineItemsSorted = new List<Received_item__c>();
               cvReceivedItemLineItemsSorted = 
                       [Select item.Name, 
                               item.Description__c
                        From Received_item__c item
                        Where item.Project_Number__c =: cvSelectedProject.id
                        ORDER BY item.Name ASC
                        limit 1000];                         
       }     
}


APEX TEST CLASS
@isTest
private class testProjectSummaryPDFController {

   static testMethod void myUnitTest() {
        
       // make a valid Project__c record we will sent to PDF controller
       Project__c lvProject = makeValidProject();
       
       // make a Sent_item__c record for the project
       Sent_item__c lvSentItemObj = makeSentItemObj(lvProject);
       
       // make a Received_item__c record for the project
       Received_item__c lvReceivedItemObj = makeReceivedItemObj(lvProject);
       
       // first get the standard controller for my object and pass in the Project obj
       ApexPages.StandardController lvStdCntrllr = new ApexPages.standardController(lvProject);

       // now create an instance of my controller
       ProjectSummaryPDFController controller = new ProjectSummaryPDFController(lvStdCntrllr);

   }
       
static private Project__c makeValidProject() {
       // create Test Project record 
       Project__c lvProj = new Project__c();
       lvProj.Name = 'Name';
   lvProj.Project_name__c = 'Project Name';
       lvProj.Contractor__c = 'Contractor';
       
       insert lvProj; 
       
       return lvProj;
   }
   
   static private Sent_item__c makeSentItemObj(Project__c pProj) {
       Sent_Item__c lvObj = new Sent_Item__c();
       lvObj.Name = 'Name';
       lvObj.Description__c = 'Description';
       lvObj.Project_Number__c = pProj.Id;
       
       insert lvObj; 
       
       return lvObj;
   }
   
   static private Received_item__c makeReceivedItemObj(Project__c pProj) {
       Received_item__c lvObj = new Received_item__c();
       lvObj.Name = 'Name';
       lvObj.Description__c = 'Description';
       lvObj.Project_Number__c = pProj.Id;
       
       insert lvObj; 
       
       return lvObj;

   }
}

 

 

Best Answer chosen by Admin (Salesforce Developers) 
econtractorproecontractorpro

I have resolved this issue. The issue was associated with the namesake.

All Answers

bob_buzzardbob_buzzard

As you are using the standard controller, the platform should retrieve that field on your behalf.  Have you confirmed that the profile of the user that is producing the PDF has appropriate field/object level access?

econtractorproecontractorpro

 

Yes..... I beleive I have. When I install the beta managed app, i select the 'Grant Access to all users' during the installation process.

 

 

bob_buzzardbob_buzzard

I'd be inclined to check the CRUD permissions and FLS for the user's profile, to rule it out at least.

econtractorproecontractorpro

Hi. Unfortuantly i cannot insert screenshots here but I checked the CRUD and FLS earlier and all of the boxes are checked.

econtractorproecontractorpro

I have resolved this issue. The issue was associated with the namesake.

This was selected as the best answer
rm1rm1
What was the solution?
Craig Rosenbaum 6Craig Rosenbaum 6
I have this exact same problem. How did you solve it?