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
Nick KeehanNick Keehan 

Displaying Results from {Parent Account > Child Account > Opportunities}

HI Guys.

Cant seem to get the Opportunities to appear under the child accounts when querying with the below codes. I can get all opportunities associated to the parent account however not able to display the Opportunites under the child accounts.

Any help would be awesome, see below for codes.

SOQL Query
public class GetAccountContacts {        
    public List<Account> getAccConCases(){
        return [select id, Name, Siebel_Row_Id__c, Parent_Accounts__c, (select id, Name from Account.Contacts) , (select id, Name from Account.Child_Accounts__r), (select id, CaseNumber from Cases), (select id, Name, AccountId from Account.Opportunities) from account where (Siebel_Row_Id__c != null Or Parent_Accounts__c != null)      LIMIT 10];
    }                   
}
VF Page displaying the results. Works like a tree map. 
<apex:repeat value="{!AccConCases}" var="a">
            <ul>
                <li>
                    <span><i class="icon-folder-open icon-plus-sign"></i>Parent Account</span> <a href="/{a.Id}"  target="_blank">{!a.Name}</a>
                    <ul>
                                        
                          <apex:repeat value="{!a.Opportunities}" var="op">
                            <li>
                                <span><i class="glyphicon glyphicon-briefcase"></i> Opportunity</span><a href="/{!op.Id}" target="_blank"></a> {!op.Name}
                            </li>
                          </apex:repeat>   
   
                        
                          <apex:repeat value="{!a.Child_Accounts__r}" var="ch">
                            <li>
                                <span><i class="glyphicon glyphicon-user"></i>Connection Accounts</span><a href="/{!ch.Id}"  target="_blank"></a> {!ch.Name}
                                <ul>
                                
                                    <apex:repeat value="{!a.Opportunities}" var="op">
                                        <li>
                                            <span><i class="glyphicon glyphicon-briefcase"></i> Opp</span><a href="/{!op.Id}" target="_blank"></a> {!op.Name}
                                        </li>
                                    </apex:repeat>
                                    
                                </ul>
                            </li>
                        </apex:repeat>                      
                    </ul>
                </li>
            </ul>
        </apex:repeat>

What it looks like currently, im looking to get opportunities to appear under the Child Accounts also.
User-added image
 
Best Answer chosen by Nick Keehan
Khan AnasKhan Anas (Salesforce Developers) 
Hi Nick,

I trust you are doing very well.

Please refer to the below blogs which has sample code which might help you with the above issue. Kindly try to implement according to your requirement.

http://forcetree.com/2011/04/tree-view-in-visualforce-page.html

http://forceschool.blogspot.com/2011/06/show-hierarchy-in-visualforce-page.html

http://salesforceblogger.blogspot.com/2012/03/hierarchy-in-visualforce.html


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Nick,

I trust you are doing very well.

Please refer to the below blogs which has sample code which might help you with the above issue. Kindly try to implement according to your requirement.

http://forcetree.com/2011/04/tree-view-in-visualforce-page.html

http://forceschool.blogspot.com/2011/06/show-hierarchy-in-visualforce-page.html

http://salesforceblogger.blogspot.com/2012/03/hierarchy-in-visualforce.html


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas
This was selected as the best answer
tejaswi dahariya 10tejaswi dahariya 10
Do you have solution of this using lightning web component?