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
John OhlmeyerJohn Ohlmeyer 

Error: Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field

Hello,
Having trouble editing some Visualforce code.  I'm trying to edit the AccountHierarchyTree component from the Inline Account Hierarchy Visualforce page (https://appexchange.salesforce.com/listingDetail?listingId=a0N300000016chCEAQ) so it shows a custom Account field, but I get a "Content cannot be displayed: SObject row was retrieved via SOQL without querying the requested field: Account.Project__c" error.  Edited section of code:

       <!-- Include the following if you uses sites with accounts -->

            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Type}" rendered="{!IF(pos.account.Type != '', true, false)}"/>
            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Name}" rendered="{!IF(pos.account.Name!= '', true, false)}"/>
            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Industry}" rendered="{!IF(pos.account.Industry!= '', true, false)}"/>&nbsp;
<!-- Stop -->

If I change account.Project__c to account.Name, Industry, or Type it works fine; all other fields I've tested don't.

Wondering if the component needs to be told to look up the field for information?  Whatever it is, I've got no idea how to make it happen - any advice would be much appreciated.

Thanks
Best Answer chosen by John Ohlmeyer
Prashant Pandey07Prashant Pandey07
You need to go Setup- Apex class and then search for AccountStructure
and send me the code..

--
Thanks,
Prashant

All Answers

Prashant Pandey07Prashant Pandey07
John,

You need to add the Project__c in the query..
 
--
Thanks,
Prashant
John OhlmeyerJohn Ohlmeyer
Hello Prashant,

Sorry, I copied and pasted the code after modifying it for another edit / test; it still throws the same error message up when it is:

       <!-- Include the following if you uses sites with accounts -->

            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Type}" rendered="{!IF(pos.account.Type != '', true, false)}"/>
            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Project__c}" rendered="{!IF(pos.account.Project__c!= '', true, false)}"/>
            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Industry}" rendered="{!IF(pos.account.Industry!= '', true, false)}"/>&nbsp;
<!-- Stop -->

Or have I misunderstood your suggestion?

Regards,
John
Prashant Pandey07Prashant Pandey07
There will be a controller associated with this visualforce page..you need to add the project__c in the query.

or you can just me class will update for you..

--
Thanks,
Prashant
John OhlmeyerJohn Ohlmeyer
Sorry, what is the controller exactly / where can I find it?  Full component code:

<apex:component Controller="AccountStructure">
    <apex:attribute name="value" type="String" description="TODO: Describe me"/>
    <apex:attribute name="currentId" description="This is the Account Id for displaying Acccount Hierarchy" type="String" required="true" assignTo="{!currentId}"/>

    <div class="treeNode">
            <apex:repeat value="{!ObjectStructure}" var="pos" >
            <apex:repeat value="{!pos.levelFlag}" var="flag" first="0">
                <apex:image url="/img/tree/empty.gif" height="16" width="20" rendered="{!IF(flag,false,true)}"/>
                <apex:image url="/s.gif" alt="" width="3" height="16" rendered="{!IF(flag,true,false)}"/>
                <apex:image url="/img/tree/chain.gif" height="16" width="20" rendered="{!IF(flag,true,false)}"/>
            </apex:repeat>

            <span height="16" v="top">

            <apex:outputText rendered="{!IF(pos.nodeType=='start',true,false)}">
                <apex:image id="tree_start" url="/img/tree/minusStart.gif" height="16" width="20" title="Click to expand/collapse nested items." onClick="TreeNodeElement.prototype.toggle(this,'{!pos.nodeId}')"/>
                <apex:image id="Icon_start" url="/img/icon/custom51_100/globe16.png" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>
                <apex:image id="Icon_start_current" url="/img/icon/star16.png" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
            </apex:outputText>
            <apex:outputText rendered="{!IF(OR(pos.nodeType=='parent',pos.nodeType=='parent_end'),true,false)}">
                <apex:image id="Tree_parent" url="/img/tree/minus.gif" rendered="{!IF(pos.nodeType=='parent',true,false)}" height="16" width="20" title="Click to expand/collapse nested items." onClick="TreeNodeElement.prototype.toggle(this,'{!pos.nodeId}')"/>
                <apex:image id="Tree_parent_end" url="/img/tree/minusEnd.gif" rendered="{!IF(pos.nodeType=='parent_end',true,false)}" height="16" width="20" title="Click to expand/collapse nested items." onClick="TreeNodeElement.prototype.toggle(this,'{!pos.nodeId}')"/>                
                <apex:image id="Icon_parent" url="/img/icon/factory16.png" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>
                <apex:image id="Icon_parent_current" url="/img/icon/star16.png" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
            </apex:outputText>
            <apex:outputText rendered="{!IF(OR(pos.nodeType=='child',pos.nodeType=='child_end'),true,false)}">
                <apex:image id="Tree_child" url="/img/tree/node.gif" rendered="{!IF(pos.nodeType=='child',true,false)}" height="16" width="20" title="Click to expand/collapse nested items." onClick="TreeNodeElement.prototype.toggle(this,'{!pos.nodeId}')"/>
                <apex:image id="Tree_child_current" url="/img/tree/nodeEnd.gif" rendered="{!IF(pos.nodeType=='child_end',true,false)}" height="16" width="20" title="Click to expand/collapse nested items." onClick="TreeNodeElement.prototype.toggle(this,'{!pos.nodeId}')"/>
                <apex:image id="Icon_child" url="/img/icon/desk16.png" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>    
                <apex:image id="Icon_child_current" url="/img/icon/star16.png" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
            </apex:outputText>
            <apex:outputText rendered="{!IF(pos.nodeType=='end',true,false)}">
                <apex:image id="Tree_end" url="/img/tree/nodeEnd.gif" height="16" width="20"/>&nbsp;
                <apex:image id="Icon_end" url="/img/icon/desk16.png" width="16" height="16" rendered="{!IF(pos.currentNode,false,true)}"/>
                <apex:image id="Icon_end_current" url="/img/icon/star16.png" width="16" height="16" rendered="{!IF(pos.currentNode,true,false)}"/>
            </apex:outputText>
<!-- Change Below -->
            <apex:outputLink value="/{!pos.account.id}" style="{!IF(pos.currentNode,'font-weight: bold;','')}" styleClass="columnHeadActiveBlack" target="_top">{!pos.account.name}</apex:outputLink>

<!-- Include the following if you uses sites with accounts -->

            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Type}" rendered="{!IF(pos.account.Type != '', true, false)}"/>
            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Project__c}" rendered="{!IF(pos.account.Project__c!= '', true, false)}"/>
            <apex:outputText style="{!IF(pos.currentNode,'font-weight: bold;','')}" value=", {!pos.account.Industry}" rendered="{!IF(pos.account.Industry!= '', true, false)}"/>&nbsp;
<!-- Stop -->
            </span>
            <div> </div>
            <apex:outputText rendered="{!IF(OR(pos.nodeType=='child_end',pos.nodeType=='child'),false,true)}">
                <div id='{!pos.nodeId}'>
            </apex:outputText>
            <apex:outputText rendered="{!IF(OR(pos.nodeType=='child_end',pos.nodeType=='child'),true,false)}">
                <div id='{!pos.nodeId}'><apex:image url="/s.gif" alt="" width="1" height="1"/></div>
            </apex:outputText>
            <apex:repeat value="{!pos.closeFlag}" var="close">
                </div>
            </apex:repeat>            

    </apex:repeat>
    <br/><br/><br/>
    </div>
</apex:component>

Thanks for your help - this is the first time I've played with Visualforce and my coding skills are poor, so apologies if I'm asking stupid questions!
Prashant Pandey07Prashant Pandey07
You need to go Setup- Apex class and then search for AccountStructure
and send me the code..

--
Thanks,
Prashant
This was selected as the best answer
John OhlmeyerJohn Ohlmeyer
Thanks for that - managed to find what I needed in the Apex and it all works now - thanks very much for your help.
John OhlmeyerJohn Ohlmeyer
Hey Prashant,

Thanks again - the page loads fine when it is part of a standard account page layout:

User-added image

However, I get an error code when I try clicking on the preview button on the Visualforce Pages Developer page: "Assertion Failed: sObject ID must be provided: Same value: null."

Any ideas?

TVM,
John
Prashant Pandey07Prashant Pandey07
Hi John,

You need to project the object ID..that means just don't preview the page try to view with an associated object.

--
Thanks,
Prashant
John OhlmeyerJohn Ohlmeyer
So if I want to view the Inline Account Hierarchy Visualforce page as it's own page I'll have to build one for it?

Thanks,
John
Prashant Pandey07Prashant Pandey07
I didn't get your question..but if you need to view the account hierarchy then you need to pass the id of an account

I belive "head office, Goulburn, BSW, Gov ,other" is an account so this record id you need to pass while you are previewing the page..
John OhlmeyerJohn Ohlmeyer
Thanks Prashant, I'll try to explain things better.

Currently the code loads fine when it is part of the existing page:
User-added image

However, I also want to be able to view the same information on it's own page, like you can using the existing view hierarchy link:
User-added image

If I go to the Develop Visualforce Pages page there is a preview link:
User-added image

But the page that loads gets this error:
User-added image
If I understand things correctly the current code will only work when it is loaded in an actual account page, as it is getting the Account ID from that page:
<apex:page standardController="account" tabStyle="Account" >
    <div style="height: 200px" class="bodyDiv" onclick="resizeFrame();">
        <c:AccountHierarchyTree currentId="{!Account.id}" />
    </div>
</apex:page>

How do I edit this code so if I am on the "Top Level" account page and click a link to open the Visualforce page in it's own tab, the Visualforce page will pull the Account ID from the "Top Level" account page?

Regards,

John
Prashant Pandey07Prashant Pandey07
Yes...the code is behaving correct...if you want to avoid this error you may add the exception in the class..

In the first image, you are able to view the result because it is tied to an account whereas in the second image it is not tied to any account and that resulting an error message.

Hope this is clear now and please select the best answer to close this thread.

--
Thanks,
Prashant
John OhlmeyerJohn Ohlmeyer
Hello Prashant,

"...in the second image it is not tied to any account and that resulting an error message."  Yes, I gethered that - what I'm asking is, how do I tie it to an account when I load the code in a new tab?

Regards,

John