function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DekorDekor 

Using aggregated values within a class

I have created this VF page:

 

<apex:page controller="casebyasset" >
  <apex:pageBlock >
        <apex:pageBlockTable value="{!casesbyasset}" var="c">  
        <apex:column value="{!c.AssetId}"/>
        <apex:column value="{!c.asset.product2id}"/>   
         
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

 

Which is using this Apex class:

 

public with sharing class casebyasset {
    public List<Case> getCasesbyasset() {
        return [SELECT assetid, asset.Product2Id FROM Case
                WHERE assetid !=null and CreatedDate = this_month limit 200];
    }
}

 

 

The issue I am having is that I want to use count function in this class grouped by assetid.  The aim is so that my VF page will display a list of assets, their product name, number of cases logged this month.

 

Have to excuse me as quite new to this and just struggling to get my head round this function.  Appreciate any feedback.

dmchengdmcheng

Have you looked at the "Working with SOQL Aggregate Functions" section on page 59 of the Apex reference manual?  You'll get an AggregateResult object and you'll have to cast the contents back to Case records.