-
How to show Contracts of Account according to hierarchy on VF page?
Account is one object and Contract is another object.
I want to show Contracts of all Child Accounts on Ultimate Parent Account.
Below is the code for same.
**Controller**
public AccountHierarchyController(ApexPages.StandardController controller) { this.acc = (Account)controller.getRecord(); this.accountList = new List<Account>(); Account baseAccount = [SELECT Id, ParentId, Name, Parent.Name, (SELECT ContractNumber,SBQQ__ActiveContract__c,StartDate,Contract_renewed__c FROM Contracts), (SELECT Id, Name FROM ChildAccounts) FROM Account WHERE Id = :acc.id]; accountList.add(baseAccount); // Traverse the hierarchy downwards Set<Id> accountsToQuery = new Map<Id, Account>(baseAccount.ChildAccounts).keySet(); while (accountsToQuery.size() > 0) { List<Account> thisLevelAccounts = [SELECT Id, Name, Parent.Name, (SELECT ContractNumber,SBQQ__ActiveContract__c,StartDate,Contract_renewed__c FROM Contracts), (SELECT Id, Name FROM ChildAccounts) FROM Account WHERE Id IN :accountsToQuery]; accountsToQuery = new Set<Id>(); for (Account a : thisLevelAccounts) { // Add this Account (with its Contracts) to the list. accountList.add(a); // Add this Account's children to the query for the next level. for (Account child : a.ChildAccounts) { accountsToQuery.add(child.Id); } } } } }**Vf Page**
<apex:page title="Contract" standardController="Account" extensions="AccountHierarchyController"> <apex:outputPanel id="cont"> <apex:pageBlock title="Contracts"> <apex:repeat value="{! accountList }" var="a"> <apex:pageBlockSection title="{! a.Name + IF(NOT(ISBLANK(a.ParentId)), ' (child of ' + a.Parent.Name + ')', '') }"> <apex:pageBlockTable value="{! a.Contracts }" var="con" id="conlist" title="Contract"> <apex:column value="{!con.ContractNumber}"/> <apex:column value="{!con.SBQQ__ActiveContract__c}" /> <apex:column value="{!con.StartDate}" /> <apex:column value="{!con.Contract_renewed__c}" /> </apex:pageBlockTable> </apex:pageBlockSection> </apex:repeat> </apex:pageBlock> </apex:outputPanel> </apex:page>But when I am trying to save it's showing:
Compile error:Unexpected token 'AccountHierarchyController'.
Can someone can help me on this.
Log In to reply.
Popular Salesforce Blogs
Learn About Salesforce Einstein Prediction Builder
The Einstein Prediction Builder can help you predict which opportunities will close and which goods prospects will buy. Predictions may be created based on the…
Why CRM is Essential for SMBs: 8 Reasons You Should Start Using a CRM
Small business owners and startups have a common challenge over years and years. Competing with larger competitors! As large corporations have more size and resources, gaining…
How to Use Wrapper Class In Salesforce Lightning Component?
How to Use Wrapper Class In Salesforce Lightning Component? A wrapper or container class is a class, a data structure, or an abstract data type…
Popular Salesforce Videos
Security in Salesforce | Security Levels in Salesforce | Salesforce Training
This "???????? ?? ??????????" video by Edureka will help you understand the different levels of security in Salesforce. It will also talk about some of…
Introduction to Salesforce CMS
Salesforce CMS is a hybrid content management system, where you can curate and share content, manage multiple language versions of your content, and control who creates…
Popular Salesforce Infographics
Salesforce CRM Integration With External Systems
Salesforce integration is one of the most important aspects of Salesforce services. It allows businesses to keep their Salesforce environment up and running. Integration Features…
Top-notch Salesforce Development Services and Consulting
Our top-notch Salesforce development services. As a Salesforce Development Services partner, we have access to a wide range of resources and support from Salesforce, including training,…
Salesforce: Giving Buzz In Numbers
Salesforce has been coined as the world’s top CRM and there is always a constant buzz around it’s latest developments. So let’s check out what…