-
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
AI, Sustainability, and Innovation: Highlights from Dreamforce 2023
Dreamforce 2023 Key Takeaways Dreamforce 2023 was the largest and most successful Dreamforce yet, with over 180,000 attendees from all over the world. The conference…
Tips To Use Salesforce Effectively, With Salesforce Online Training
Salesforce is one of the most popular CRM platforms. In recent years, there is a massive increase in the number of companies that are proudly…
The Benefits of Hiring a Salesforce Nonprofit Consultant for Your Organization
Nonprofits are often challenged to manually administer donor details, program data, and other critical information due to a lack of resources, time, and funding. This…
Popular Salesforce Videos
Extend your Reporting Strategy with AppExchange | Reports & Dashboards | Salesforce
This Salesforce Tutorial is ideal for both beginners as well as professionals who want to master Salesforce Cloud. Below are the topics covered in this…
EPC and CPQ in Salesforce Industries (Vlocity)
Enterprise Product Catalog (EPC) to configure and manage CPQ in one place. It's a guided selling experience for users to build an order. While CPQ…
Customer Overview: How Our Customer Used Salesforce Industries i.e Vlocity For It’s Business?
Let's have a glance at our customer success story to understand what is Salesforce Industries in detail. Watch this video and do let us know…
Popular Salesforce Infographics
Top Salesforce Acquisitions Of All Time and In 2020
Salesforce has been on a shopping spree over the last few years. We all read quite frequently about Salesforce acquisitions. They are quick enough to…
Salesforce CPQ, AI for Smart Selling
Sales teams embracing AI are seeing an expansion in leads and arrangements of over half, cost decreases of 40%–60%, and call time decreases of 60%–70%,…
Salesforce Solutions For Travel Agencies
Salesforce for Travel is more than just a CRM. It’s a comprehensive ecosystem designed to empower travel agencies of all sizes. Comprehensive solutions offered by…