You need to sign in to do that
Don't have an account?
tobibeer
Template composition and SOQL exception
Can someone explain, why this VisualForce page...
<apex:page showHeader="false" standardStylesheets="false" standardController="SitePage__c" extensions="pageController"> <apex:composition template="{!myTemplate}"> <apex:define name="content"> <apex:outputText escape="false" value="{!SitePage__c.Content__c}"/> </apex:define> </apex:composition> </apex:page>
produces the following exception...
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: SitePage__c.Content__c
...yet the following, modified version of the page - introducing a quite redundant variable - does work...
<apex:page showHeader="false" standardStylesheets="false" standardController="SitePage__c" extensions="pageController"> <apex:variable var="c" value="{!SitePage__c.Content__c}"/> <apex:composition template="{!myTemplate}"> <apex:define name="content"> <apex:outputText escape="false" value="{!c}"/> </apex:define> </apex:composition> </apex:page>
?
The controller should be of no concern but looks like this...
public class pageController { private final SitePage__c sitepage; public pageController(ApexPages.StandardController stdController) { this.sitepage = (SitePage__c)stdController.getRecord(); } public PageReference getmyTemplate() { return Page.tplDefault; } }
Hi tobibeer,
Your code is correct, dunno why sometimes we face this weird behaviour.
You can get rid of it by querying in controller, but that too will be using redundant variable.
Eg:
Was just an Idea, let me know if you find some better solution.
Hi Rahut,
Thanks for your suggestion, although it wasn't quite sufficient to actually work. What I had to do was to provide a getter which I called getsitepage(), to eventually retrieve the custom field content in the VisualForce page via {!sitepage.Content__c}.
The controller now looks like this:
and my page now looks like this...
I have no idea as to whether or not such a proceeding would introduce code vulnerabilities... nontheless, I have tried to declare the variable sitepage as public without using a dedicated getter, like this...
That , however, in combination with the following changes...
...to my VisualForce page, nothing at all was retrieved, just like your code.
Any other ideas outthere on how to clear the code from such (seemingly) redundant accessors, please let me know.
Cheers, Tobias.