-
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
Benefits of Salesforce Custom Development in 2024| Greytrix
Whether you agree with me or not, Salesforce is among the most potent CRM solutions on the market. With its many amazing features, functionalities, and…
Top Salesforce Data Integration Strategies for Seamless Workflow
Efficient data management is critical for modern organizations aiming to make informed decisions and maintain a competitive edge. Salesforce data integration offers a structured approach…
Creating a Salesforce Extension: From Idea to Listing on Appexchange
With more than 6 million AppExchange installs, it's no wonder that 89% of Fortune 100 companies are using apps from Salesforce's AppExchange to get things done smoothly…
Popular Salesforce Videos
Salesforce JavaScript Developer 1 Certification Series
Hi Everyone, SFDC Panther has started the Salesforce JavaScript Certification series and this is the first session. What you will learn: Variables Data Types Operators…
The Power Of Displaying Salesforce Data in Google Maps
Ever wondered where on earth your Leads are? Or your customers and prospects for that matter? Well here’s the way to find out. Display your…
What is Apex? | Way to become a Salesforce Developer
Apex is a development platform for building software as a service (SaaS) applications on top of Salesforce's customer relationship management (CRM) functionality. Apex allows developers…
Popular Salesforce Infographics
Salesforce Experience Cloud Benefits For Business Growth
Explore How Salesforce Experience Cloud Can Help Your Business? Get bespoke solutions including: Data integration, time & cost savings.
How Can Your Company Benefit from Salesforce Community Cloud
Salesforce Community Cloud is an online platform where companies can connect customers, partners, and employees with each other and the data or records they need…
The ROI of Building Apps on Salesforce
With our ROI Calculator, embark on a journey to discover how much more productive your organization can be when building apps using the Salesforce Platform.…