-
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
Open Web Application Security Project | Salesforce Security Guide
Why Is OWASP Important to You? OWASP represents the Open Web Application Security Project. This open-source project gets the news out about application security weaknesses,…
Accelerating Vaccine Management With Salesforce's Vaccine Cloud
Local and international government officials and healthcare workers are currently delivering the most extensive mass vaccination campaign in human history. The formulation and creation of…
11 Top Training Resources To Master Salesforce
As the most powerful customer relationship management (CRM) resource in sales and marketing, Salesforce is in demand helping subscribers increase contacts and sales revenue every…
Popular Salesforce Videos
Salesforce Lightning: Custom Theming and Branding
As part of myLightning, Custom Theming and Branding for Lightning Experience lets you customize key styling elements, such as the global header color, brand image,…
Relationships in Salesforce | Why Relationships are Created?
In this video, Salesforce Rangers goes into detail about what relationships are in Salesforce and why they are necessary in the first place. This is…
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…
Popular Salesforce Infographics
Why Salesforce End-user Training Matters for Smooth Implementation
This infographic 'Why Salesforce end-user training matters for smooth implementation' appeared first on Cynoteck. The progress of any CRM implementation depends on its general adoption…
How Sales Reps are Staying at the Top of Their Game | Salesforce Guide
Sales reps around the world had to rapidly adopt new methods to work around lockdowns and travel restrictions. In some cases, this meant learning new…
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.…