-
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…
No Code Salesforce and HubSpot Integration
Leverage inbound marketing's potential and integrate sales channels to align the internal teams responsible for both operations. Huge opportunities are created by connecting HubSpot and…
Salesforce Business Processes - Learn Here!
Salesforce is a leading customer relationship management (CRM) platform that helps businesses streamline and automate various processes. With its wide range of tools and features,…
Popular Salesforce Videos
Salesforce Resume Review
Salesforce is a well-known company and leader in the cloud computing space so we would say it would be an asset on a resume. Thinking…
How to Become a Salesforce Consultant at Any Age
Companies are in great demand of skilled Salesforce consultants as a means to achieve their Salesforce objectives for better output in their business. With the…
Demystifying OAuth and Connected Apps
Often times, the first thing an application needs to do is authenticate its users. Developers building integrations with Salesforce need a simple and secure way…
Popular Salesforce Infographics
Step by Step: What you Should Know About the Order-to-Cash Process
The order-to-cash (O2C) process is a defining part of a company’s success, and it also plays a big role in driving an organization’s relationship with…
Timing is Everything : Understanding B2B Buyer Behavior
B2B buyer activity and research peaks at different times of the year, week, and day. Software Advice conducted a study gathering data from six million…
What is Salesforce Customer 360?
According to our State of the Connected Customer report, 76% of customers expect consistent interactions across departments. However, 54% say it often feels like sales, service,…