-
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 can Organizations Benefit From Salesforce Sales Cloud Implementation
Businesses today, irrespective of their scope or size need a feasible platform to pull through the fierce marketplace competition, nurture the existing customers, and acquire…
Create Multiple Records Of Different Salesforce Objects
Here we have a demo what we achieve through the code. What you need is to follow the below steps. Also, I welcome you guys…
Landing Page Login Form And Save Data In Salesforce Data Extensions
As all we know, Salesforce Marketing Cloud is a tool that provides digital marketing automation and services and analytics software. And Landing page is an…
Popular Salesforce Videos
Nested Lists in Apex | Salesforce Development Tutorial for Beginners
In this video, Shrey has explained in detail the process to create a Nested List in Apex. Watch the full video to understand. If you…
Maximizing Salesforce Lightning Experience and Lightning Component Performance
00:04:57 - Agenda 00:06:08 - Difference between Salesforce Classic and Salesforce Lightning 00:17:45 - Demo: Load time comparison between Salesforce Classic and Salesforce Lightning when…
Things you can do with Loyalty Management in Salesforce to Create Lifelong Customers
Although keeping customers is not always simple, statistics show that when they are a part of an ongoing customer loyalty management program, they spend 67%…
Popular Salesforce Infographics
How a CRM Platform can Immediately Impact your Business
Selecting the best CRM for small businesses is not a one-size-fits-all endeavor. If you’re new to working with a CRM platform, you often have to…
Salesforce CRM Integration With External Systems
Salesforce integration is one of the most important aspects of Salesforce services. It allows businesses to keep their Salesforce environment up and running. Integration Features…
Customer Service: The Forgotten Marketing Channel
The key to good customer service is building good relationships with your customers. Thanking the customer and promoting a positive, helpful and friendly environment will…