3

I need to use group by cube to display the count of added services for each group for each package. I get an error on line 18: method does not exist or incorrect signature: void get(String) from the type List. How do I correct for this?

public class AddedServicesGrouping {

    public list<Inspection__c> inspections = [SELECT Id, (SELECT Added_Services_Group__c, Inspection_Package__c, Id
                                   FROM Inspection_Services__r)
                                   FROM Inspection__c
                                   WHERE Status__c = 'Completed' AND Month_Since_Launch__c > 0];

    public list<Inspection__c> getservices(){

        for(Inspection__c i: inspections){
            for(Inspection_Service__c addedservices : i.Inspection_Services__r){
                AggregateResult[] ar =
                    [SELECT Added_Services_Group__c AddedService, count_distinct(id) cnt, Inspection_Package__c Package,
                    GROUPING(Added_Services_Group__c), GROUPING(Inspection_Package__c) 
                    FROM Inspection_Service__c
                    GROUP BY CUBE (Added_Services_Group__c, Inspection_Package__c)];

                integer n = integer.valueof(ar.get('cnt'));
            }
        } 
        return inspections;
    }
}

2 Answers 2

11

You need to call get from AggregateResult, not List<AggregateResult>.

Instead of ar.get('cnt'), you could for instance do ar[0].get('cnt').

8

ar is of type AggregateResult[] (also known as List<AggregateResult>). You are aliasing correctly, but you must call get() on a single AggregateResult.

Reference: Working with SOQL Aggregate Functions.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .