I have created one VF page which is on Account object to show the Account Hierarchy at the parent level. Basically this VF page will show Contracts of all child Accounts on parent account.
I have added this page as a related list on Account layout.
Also I have added two buttons New Contract & Renew Contract which are part of Salesforce CPQ managed package.
I am trying to create wrapper class so that we can select Multiple Contract record to Renew Contracts from Parent Account.
I have created the hierarchy which shows the contract of child accounts .
But i am unable to create wrapper class for the same. Can someone help me out.
VF page
<apex:page title="Contract" standardController="Account" extensions="AccountHierarchyController">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:outputPanel id="cont">
<apex:pageBlock title="Contracts">
<apex:repeat value="{!wrapaccountList}" var="a">
<apex:pageBlockSection title="{! a.Name + IF(NOT(ISBLANK(a.ParentId)), ' (child of ' + a.Parent.Name + ')', '') }">
<apex:commandLink value="New Contract" action="{!newContract}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;" />
<apex:commandLink value="Renew Contract" action="{!renewContract}" target="_parent" styleClass="btn" style="text-decoration:none;padding:4px;" />
<apex:pageBlockTable value="{! wrapaccountList }" var="con" title="Contract">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox id="chkbox" onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!con.selected}" id="inputId" />
</apex:column>
<apex:column HeaderValue="Action" width="60">
<apex:commandLink value="Edit" action="{!editContract}" target="_parent"><apex:param value="{!con.id}" name="contractId"/> </apex:commandLink>
</apex:column>
<apex:column headerValue="Contract Number"><apex:outputLink value="/{!con.id}" target="_blank">{!con.ContractNumber}</apex:outputLink> </apex:column>
<apex:column value="{!con.SBQQ__ActiveContract__c}" />
<apex:column value="{!con.StartDate}" />
<apex:column value="{!con.EndDate}" />
<apex:column value="{!con.Contract_renewed__c}" />
</apex:pageBlockTable>
<apex:outputLabel value="No records to display" rendered="{!(ISNULL(a.Contracts))}" styleClass="noRowsHeader"></apex:outputLabel>
</apex:pageBlockSection>
</apex:repeat>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
Controller
public with sharing class AccountHierarchyController {
public Account acc { get; private set; }
// public List<Account> accountList { get; private set; }
public List<wrapAccount> wrapaccountList { get; set; }
public List<Account> selectedAccounts{get;set;}
public ApexPages.StandardController controller { get; set; }
public AccountHierarchyController (ApexPages.StandardController controller) {
this.acc = (Account)controller.getRecord();
this.wrapaccountList = new List<wrapAccount>();
Account baseAccount = [SELECT Id,
ParentId,
Name,
Parent.Name,
(SELECT ContractNumber,SBQQ__ActiveContract__c,StartDate,EndDate,Contract_renewed__c FROM Contracts),
(SELECT Id, Name FROM ChildAccounts)
FROM Account
WHERE Id = :acc.id];
wrapaccountList.add(new wrapAccount(baseAccount));
//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,EndDate,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.
wrapaccountList.add(a);
// Add this Account's children to the query for the next level.
for (Account child : a.ChildAccounts) {
accountsToQuery.add(child.Id);
}
}
}
}
//This method is to create a new contract while clicking on the Add contract button
public pageReference newContract(){
pageReference pageRef = new pageReference(URL.getSalesforceBaseUrl().toExternalForm() + '/800/e?&retURL=' + acc.id);
return pageRef;
}
//This method is to renew contract while clicking on the Renew contract button
public void renewContract() {
selectedAccounts = new List<Account>();
for(wrapAccount wrapAccountObj : wrapaccountList) {
if(wrapAccountObj.selected == true) {
selectedAccounts.add(wrapAccountObj.acc);
}
}
}
// public pageReference renewContract(){
// pageReference pageRef = new pageReference(URL.getSalesforceBaseUrl().toExternalForm() + '/800/e?&retURL=' + acc.id);
// pageReference p = new pageReference('/apex/SBQQ__RenewContracts');
// p.setRedirect(true);
// return p;
// }
//This method is to edit the existing contact record while clicking the Edit link
public pageReference editContract(){
String contractId = Apexpages.currentpage().getParameters().get('contractId');
pageReference pageRef = new pageReference(URL.getSalesforceBaseUrl().toExternalForm() + '/' + contractId + '/e?retURL=' + acc.id);
return pageRef;
}
// This is our wrapper/container class. A container class is a class, a data structure, or an
abstract
data type whose instances are collections of other objects. In this example a wrapper class contains
both the standard salesforce object Account and a Boolean value
public class wrapaccountList {
public Account acc {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new wrapAccount object we pass a Account that is set to the acc property. We also set the selected value to false
public wrapaccountList(Account a) {
acc = a;
selected = false;
}
}
}
Error:
Need some expert advice on this.
When I am trying to save it is throwing error: