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
BrianWKBrianWK 

PageReference issue when using same extension for 3 pages

Hey everyone, I've run into something that I'm a bit perplex on.

 

I have a 3 page wizard. Page 1. (SalesPAWizard1) Contains some inputText boxes that populate a get/set methods in my Extension.

 

Page 2. (SalesPAWizard2)Is a "Preview" of page 3 using apex : include.

 

My issue is when a user fills out the inputtext boxes on page and clicks my command button to go to the next page I get an error:

"System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.CloseDate"

 

I'm confused since if I load Page 2 separately (without going through page 1) it loads perfectly fine.  All my pages have the same standardcontroller and using the same extension. I've tried just copying the code from Page 3 directly to Page 2 instead of using the Apex : include option - but I get the same result.

 

PageReference Code in Controller Extension:

public PageReference NextStep2()
{
return page.SalesPAWizard2;
}

 

 

Code in Page 2

<apex:page StandardController="Opportunity" extensions="OpportunityPAWizardExtension">
<apex:include pageName="SalesPAPDF" />
</apex:page>

 

Code in Page 3 that's in the error

 

<apex:page standardcontroller="Opportunity" extensions="OpportunityPAWizardExtension" > 

<apex:outputlabel value="Purchase Proposal Date: " style="font-weight:bold"/ >
<apex:outputfield value="{!Opportunity.CloseDate}" /> <br/>

I've tried commenting this out - but it appears anytime in Page 3 where I'm calling the Opportunity fields (standard Controller being used).

 

I've tried creating a new PageReference, setting the redirect to true and putting the OpportunityID as a parameter - but this didn't carry over the input fields from Page1. Anyone have any suggestions or recommendations of where to look?

BrianWKBrianWK

I got an update for everyone. I stumbled upont his completely by mistake.

 

My page 2 that receiving the SOQL error - desite using the same StandardController and Extension will work if the fields I request are also on page 1. All Page 2 does is an Include to Page 3.

 

For my test Example I removed all my fields excet Opportunity.CloseDate as a outputfield on Page 3. This is field mentioned in the SOQL error. Attempting to go from Page 1 to Page 2 gives me the same SOQL Error. On Page 1 I add Opportunity.CloseDate as an outputfield and save. Now if I attempt to go from Page 1 to Page 2 - it works!

 

It appears anytime I'm trying to refer to a standard or custom field against the Opportunity standard controller, I must include those same fields in the previous page or else I receive an SOQL error.

 

Has anyone else experienced this? Is this how it supposed to be designed or am I missing something?

Message Edited by BrianWK on 01-23-2009 12:36 PM
bunrothabunrotha

Brian-

 

I just ran up against a very similar thing, it seems my class method for deriving various parts of a form letter also can't see anything not in page one.

 

Pure conjecture on my part is that the constructor method for your controller/page only runs the SOQL to pull the fields needed at the time (ie for Page 1), and doesn't pull extra fields between pages, or look ahead to the future pages (still no AssertCrystalBall() function either ;-) )  I know that for a controller extension to see mergefields, you either have to query or put the fields on the VF page calling the methods.  This would mean, I suspect, that it works as designed, and the app is trying to be efficient, not pulling fields you don't plan to use at the time of query.

 

Can any of the more knowledgeable folks confirm or deny this theory? 

 

I can confirm I have the same issue you describe, and same workaround (lots of hidden fields in page 1) has fixed it.  Good find, you've saved me hours!

 

cheers,

Nick

BrianWKBrianWK

Bunrotha,

 

There was another thread of something similiar - unfortunately I couldn't find it.

 

Since my controller is an extension of the class my particular issue was due to a standard controller. When the first page loads, the Standard controller doesn't query the full object (in my case an Opportunity) and instead only queries for the fields reference on that page.

 

So on page two, if I ask for Opportuninty.TotalAmount but didn't ask for it on Page1 - the Opportunity object in the standard controller doesn't contain that field and therefore you get a getOpportunity error.

 

So it's not a bug, it's working "As designed" for resource purposes.