-
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
Passing Platform Developer II – MCQ made easy!
You hear it right! Now the Salesforce Platform Developer II exam is made more easy with realistic tasks and flexible deadlines (Actually no deadline, in other…
Visualizing Salesforce Metadata: Understanding the Relationships with AbstraLinx ERDs
Salesforce is an excellent platform for managing your business as it offers all the necessary features in one place, allowing you to work more efficiently.…
Salesforce Spring '23 Release Overview
Salesforce is kick-starting the year with a whole host of updates in the Spring ’23 release, some of which we’ve outlined below! It's all about…
Popular Salesforce Videos
8 Steps to Launch Your App on Salesforce AppExchange
AppExchange is the largest business app store in the world, with over 4,000 apps and millions of users. In this video, we will guide you…
MailChimp Salesforce Integration
The MailChimp and Salesforce integration allow you to start creating email campaigns from the leads and contacts in your Salesforce CRM. With the integration, it becomes easy to create list segmentation…
Salesforce Summer '18 Release
I can’t believe Summer ’18 is already here in no time. I don’t know about all of you, but I still have my winter stuff…
Popular Salesforce Infographics
Key Differences Between Salesforce Sales Cloud and Service Cloud
????? ??? ???? ?????????? ??????????? ????????? ?????????? ????? ????? ??? ??????? ?????! Dive into the key differences between these two powerful Salesforce solutions: Focus and…
Six Steps To Success With Salesforce Chatter
Salesforce Chatter helps to connect every employee with files, data, and experts they need anywhere anytime. Thereby enhancing productivity, accelerating innovation, sharing knowledge and a…
Salesforce & Blockchain : Driving Businesses at the Speed of Trust
Knowing the disrupter and the thought leader mind, Marc Benioff always has a way of looking at things with a beginners mind. With this thinking…