-
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
Discover Innovative Solutions for Salesforce Experience Cloud at Dreamforce 2022
Salesforce has been nothing short of revolutionary, since its inception. As the world’s #1 CRM platform, it has connected organizations across the globe with their…
Salesforce for Nonprofits – What Salesforce’s acquisition of Salesforce.org means for Customers
Salesforce for Nonprofits – Salesforce.com Inc. has made a rather unusual acquisition – buying its own independent philanthropic org Salesforce.org in a $300 million deal. The…
Single Sign-on (SSO) for Salesforce with Microsoft Azure AD
What Is SSO? SSO is an abbreviation of Single Sign-On. It is a method for granting access to multiple applications to users with a single…
Popular Salesforce Videos
What is APEX? | Features of APEX | Salesforce Development Course
This is the first Chapter of the Salesforce Development Course video series. In this video, Shrey has answered the following questions: What is APEX? What…
How To Create Workflow Rules In Salesforce | Salesforce Workflow Rules
This video walks through the steps to create a Workflow Rule within the Process Automation section of Lightning Settings in Salesforce. Get answers to the…
Salesforce Staff Has Option to Keep Working From Home
Dan Bognar, head of the strategy for Asia at Salesforce.com Inc., discusses how the coronavirus outbreak is affecting the San Francisco-based software maker’s operations and…
Popular Salesforce Infographics
Benefits of Salesforce Pardot Implementation
Cyntexa offers the best Salesforce Pardot Implementation services so that you can offer the best customer services. Our certified experts will provide Salesforce Pardot Implementation…
Infographic: 3 Trends That’ll Transform Small Business Growth in 2018
If you’re hoping to successfully grow your small business this year, you need to stay on top of the newest trends. Not sure where to…
Benefits of Salesforce Einstein GPT For Business Growth
Leverage the power of Salesforce Einstein GPT to boost the business growth and success, streamline workflow and take data-driven decisions. Explore now!