-
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
How does Salesforce Address the Security Challenges of Generative AI for CRM?
OpenAI released ChatGPT in November 2022 and attracted worldwide attention with its capability to deal with challenging language understanding and generation tasks in conversations. OpenAI…
What are Flow Best Practices in 2023?
There are some best practices that you must follow while working on flow. They are: Plan your Flow Before you Start Building Write or draw…
Integrate Salesforce with MuleSoft
In this blog we are focusing on Salesforce integration with MuleSoft. Firstly, we will need a Salesforce developer account by clicking on the following link:…
Popular Salesforce Videos
Salesforce CPQ from Scratch
CPQ Salesforce, or Configure, Price, Quote Software by Salesforce is a sales tool for companies to provide accurate pricing with any given product configuration scenario.…
Salesforce Apex Rest API Integration | Salesforce Integration
As you know Salesforce is an online cloud solution, we might be required to integrate Salesforce with some other third party tool. We have released…
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…
Popular Salesforce Infographics
4 Reasons To Offer An Exceptional Customer Service
When it comes to customer service, our friends at Salesforce have a few tips and tricks up their sleeve. We were thrilled to help them…
How is Salesforce Benefiting Businesses?
Salesforce is one of the top cloud-based CRM software for service, marketing, and sales. It helps in creating a more meaningful relationship with the customers.…
How to Create a Community of Trust and Gratitude with Salesforce
The businesses that will be remembered positively after COVID-19 are extending empathy and grace to their employees, customers, and communities. We’ve seen so many communities…