My trigger will send an email when an Account has 8 or more Cases created in 7 days. My first SOQL grabs Cases that fit the criteria. My second SOQL pushes the AccountIds of the Cases into a Set. My current code gets error:

Method does not exist or incorrect signature: void add(Object) from the type Set

The code

    List<AggregateResult> AggregateResultList = [SELECT AccountId, Account.Name name, COUNT(Id) co
                                    FROM Case
                                    WHERE CreatedDate = LAST_N_DAYS:5 
                                    GROUP BY AccountId, Account.Name
                                    HAVING COUNT(Id)  >= 1];

    Set<Id> AcctIds = new Set<Id>();

    for(AggregateResult aggr: AggregateResultList){
        AcctIds.add(aggr.get('AccountId'));  //  <-----HOW DO I ADD ACCOUNT ID TO MY NEW SET????

    List<Case> caseList = [SELECT Id, AccountId, Account.Name, Project__r.Implementation_status__c,
    Project__r.Client_Advisor_Email__c FROM Case WHERE AccountId IN :AcctIds];

    System.debug('This is CaseList ' + caseList);

    for(Case cl:caseList){ 
        System.debug('Implementation Status: ' + cl.get('Project__r.Implementation_status__c'));

Is there a way to typecast into an Id, or is that even the correct way to go? Thank you.

1 Answer 1


As your Set is of type of Id, you need to cast aggr.get('AccountId') to Id.

You can achieve it by



Id accId = (Id)aggr.get('AccountId');

You must log in to answer this question.

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