+ Start a Discussion
theitdeptrockstheitdeptrocks 

VF Template Error: SObject row was retrieved via SOQL without querying...

SObject row was retrieved via SOQL without querying the requested field: Plan_Process__c.Advisor_Meeting_Call__c

 

I am receiving the above error message within a VF email template where the relatedTo is set to "Plan_Process__c." 

 

Usually when I see this error message, I've forgotten to include a field in a SOQL statement, but this is a little bit different as it is just an email template, no Apex and no SOQL.

 

Has anyone seen this and what can I do to resolve it?

 

Thanks in advance!

joshbirkjoshbirk

Can you post the Visualforce?  Possible that the related field isn't going to be brought in automatically, so you might need to add an Apex extension to retrieve it.

theitdeptrockstheitdeptrocks

Ah, I'm glad you said that. 

 

This template started out as a VF page and I was receiving the same the same error message.  To resolve that, what I did was through all of the used fields into the <apex:page label="{!fields here}...

 

Now with a Visualforce template, I don't have the ability to use an extension (right?  Just the Recipient and RelatedTo?).  I also do not have an <apex:page> tag to provide the fields in the label.  I'm curious if I can created an <apex:outputpanel> with rendered=false with those fields in it.


My hypothesis of why this is occuring is when fields are used ONLY within a formula on a page, the fields are not included in a query to initially render the page.  If the field appears on the page, outside of a formula, it is included, therefore being available for use in a formula, preventing the page SOQL error from appearing.

 

Would Display the error:

 <img src="{!if(NOT(ISNULL(relatedTo.Date_Signed_Documents_Received__c)),URLFOR($Resource.Plan_Progress,'checkbox_large_checked.png'),URLFOR($Resource.Plan_Progress,'checkbox_large.png'))}" alt="" width="36" height="36" />

 

Just confirmed that this does not display the error:

<apex:outputpanel rendered="false">
  {!relatedTo.Date_Signed_Documents_Received__c}
</apex:outputpanel>

<img src="{!if(NOT(ISNULL(relatedTo.Date_Signed_Documents_Received__c)),URLFOR($Resource.Plan_Progress,'checkbox_large_checked.png'),URLFOR($Resource.Plan_Progress,'checkbox_large.png'))}" alt="" width="36" height="36" />

 

 

aballardaballard

Looks like a bug; I think it should automatically detect that the field is referenced and include it in the sql. 

 

But another workaround to make it include a field that for some reason it doesn't get automatically is to use <apex:inputHidden> .