You need to sign in to do that
Don't have an account?

Trying to add summary values to a apex:pageBlockTable
I'm just learning, so please bear with me. I'm making a case-merge application. The user selects cases to be merged and presses a list button. This launches a VF page that displays the selected cases in an apex:pageBlockTable.
I would now like to add a number of summary columns to this table. The summary columns show how many emails, tasks, attachments, etc.. each of the cases to be merged has.
In my VF page I have:
<apex:column value="{!item.CaseNumber}"/>
<apex:column value="{!item.Subject}"/>
...etc...
</apex:pageBlockTable>
In my class I have:
public Case[] getSelectedCases() {
Set<Id> selectedCaseIds = new Set<Id>();
for (SObject c : setCon.getSelected()) {
selectedCaseIds.add(c.Id);
}
SObject[] items = [SELECT c.Id, c.CaseNumber, c.Subject, c.Contact.Name, c.Account.Name,
c.CreatedDate, c.Origin, c.LastModifiedDate FROM Case c WHERE Id IN :selectedCaseIds];
return items;
}
I now would like to add a number columns to my table that are the results of queries like:
SELECT count() FROM CaseComment cc WHERE cc.ParentId = EACH CASE ID IN THE ABOVE SET;
so my ultimate display shows
<apex:pageBlockTable value="{!SelectedCases}" var="item">
<apex:column value="{!item.CaseNumber}"/>
<apex:column value="{!item.Subject}"/>
<apex:column value="{!item.CountOfCaseComments}" />
...etc...
</apex:pageBlockTable>
Thanks!
You can't pass parameters back from the page to getters I'm afraid.
If it were me, I'd create a custom class that contains the case sobject and any associated total information. Rather than returning a list of cases, your getter would construct a list of instances of the custom class. Then change the column output in the VF page to pull the appropriate data.
E.g. if your custom class contains a getCase() method to retrieve the case info, and a getTotal to retrieve the total, you'd have something like:
All Answers
Hi Andy,
You don't need a custom object. You just need a method to call the sums so something like this:
then in the vforce page put
but it needs to be a seperate table with a different value.
Hi Stephan,
I need to be able to get a different 'id' value for each summary query depending on the current record in the list going into the pageBlockTable... I tried this but couldn't get it to compile...:
public Integer getArtifactCount(String caseId) {
return [SELECT Count() FROM Artifact__c a WHERE a.Case__c = :caseId];
}
<apex:pageBlockTable value="{!SelectedCases}" var="item">
<apex:column value="{!item.Subject}"/>
<apex:column headerValue="Contact Name" value="{!item.Contact.Name}"/>
...etc...
<apex:column value="{!ArtifactCount(item.Id)}"/>
</apex:pageBlockTable>
I am using a list controller:
<apex:page standardController="Case"
recordSetVar="cases"
extensions="CaseMergeController">
...
does that matter?
You can't pass parameters back from the page to getters I'm afraid.
If it were me, I'd create a custom class that contains the case sobject and any associated total information. Rather than returning a list of cases, your getter would construct a list of instances of the custom class. Then change the column output in the VF page to pull the appropriate data.
E.g. if your custom class contains a getCase() method to retrieve the case info, and a getTotal to retrieve the total, you'd have something like:
Thanks Bob,
I was able to get it working with the inner class method you suggested. In the constructor for my StandardSetController extension, I create a list of 'CaseInfo' objects, each of which contains the case details and all of the summary counts I wanted to display in my table.
//Inner class used to hold a mix of case and summary values
class CaseInfo {
public Case SelectedCase = new Case();
public Integer CountActivities {get; set;}
public Integer CountCaseComments {get; set;}
public Integer CountArtifacts {get; set;}
public Integer CountEmails {get; set;}
public Integer CountLabor {get; set;}
public Case getSelectedCase() { return this.SelectedCase; }
}
From my VF page, I then display the array of CaseInfo objects as follows:
<apex:pageBlockTable value="{!MetaCases}" var="i">
<apex:column value="{!i.SelectedCase.CaseNumber}"/>
<apex:column value="{!i.SelectedCase.Subject}" headerValue="Subject/Desc" title="{!i.SelectedCase.Description}"/>
<apex:column value="{!i.SelectedCase.Contact.Name}" headerValue="Contact Name" />
...
<apex:column value="{!i.CountActivities}" headerValue="Tasks" title="Number of Activities"/> <apex:column value="{!i.CountCaseComments}" headerValue="Comments" title="Number of CaseComments"/>
...
</apex:pageBlockTable>
-Andy