1

I have a pageblocktable in which i am displaying statuses(Open,InProcess,Closed).but in object the Status__c field is picklist(stores 12 statuses like stat1,stat2,stat3 comes in Open Status sta4,stat5....stat10 comes under InProcess Status,and stat11,stat12 in Closed status).

The table should looks like

Category TotalRecords Open InProcess Closed
  cat1       8          2      1        5
  cat2       5          3      2        0

I am getting data group by Category__c field and Counting the Records which gives correct data,but how can i arrange the values in Status__c field to (Open,InProcess,Closed).

class:

 public List<Data> dt{get;set;}
 public class Data
 {
     public AggregateResult ar {get; set;}
     public String Status{get { return (string)ar.get('status'); }}
     public decimal Open { get;set;}
     public decimal InProcess { get;set;}
     public decimal Closed{ get;set;}
  } 

I am getting data and assigning to the list dt. based on the property status i need to assign values to Open,InProcess,Closed.

I tried iterating through the list dt.and checking Status value and assign to the (Open,InProcess,Closed) which is not giving the correct result.

Please help.

Thanks in advance

1

Class:

Set<String> openStatusSet = new Set<String>{'status1', 'status2', ... };
Set<String> inProcessStatusSet = new Set<String>{'status4', 'status5', ... };
Set<String> closedStatusSet = new Set<String>{'status11', 'status12', ... };

public List<Data> getDataList(){
    Map<String, Data> dataMap = new Map<String, Data>();  // dataMap: category ---> Data
    for(AggregateResult at :[SELECT count(Id) cnt, Category__c, Status__c FROM YourObject__c Group By Category__c, Status__c]{
        String category = (String)ar.get('Category__c');
        Data tempData = dataMap.get(category);
        if(tempData == null)
            tempData = new Data(category); // TODO: Create Constructor + initialize counts
        String status = (String)ar.get('Status__c');
        Decimal recordCount = (Decimal)ar.get('cnt');
        if(openStatusSet.contains(status))
            tempData.open += recordCount;
        if(inProcessStatusSet.contains(status))
            tempData.inProcess += recordCount;
        if(closedStatusSet.contains(status))
            tempData.closed += recordCount;

        dataMap.put(category,  tempData);
    }
    return dataMap.values();
}

Then render the pageBlockTable as usual

<apex: pageBlockTable value="{!DataList}" var="data">
    <apex:column columnName="Category" value="{!data.category}"/>
    <apex:column columnName="Open" value="{!data.open}"/>
    <apex:column columnName="In Process" value="{!data.inProcess}"/>
    <apex:column columnName="Closed" value="{!data.closed}"/>
</apex:pageBlockTable>
  • And i initialize Open,InProcess,Closed properties to 0 in Constructor.. – NullReferenceException Aug 6 '14 at 7:17
  • Thanks @amatorVitae.The concept works as expected but the TotalRecord count showing incorrectly. – NullReferenceException Aug 6 '14 at 7:30
  • Add a tempData.total += recordCount before it puts the data into the map – Scott Pelak Aug 6 '14 at 12:44

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.