• Felipe Czk
  • NEWBIE
  • 10 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

I have this Map, and it's on my repository class
 

public Map<Id,List<AggregateResult>> buscaPBsAtivacao(){
        Map<Id, List<AggregateResult>> membroCampanhaMap = new Map<Id, List<AggregateResult>>();
        List<String> Territories= new List<String>{
           'Some Territories Names'
        };
       
        List<AggregateResult> territorioAssociado = [
            SELECT
                Object.Name, //here is the account name
                ObjectId, // here is the account Id
                Territory2Id,
                Territory2.DeveloperName
            FROM
                ObjectTerritory2Association
            WHERE
                Territory2.DeveloperName IN : Territories
            GROUP BY
                Territory2.DeveloperName,
                Object.Name,
                ObjectId,
                Territory2Id  
            ORDER By
                Territory2.DeveloperName
        ];
        for (AggregateResult agr : territorioAssociado) {
            Id objectId = (Id) agr.get('ObjectId');
            if (!membroCampanhaMap.containsKey(objectId)) {
                membroCampanhaMap.put(objectId, new List<AggregateResult>());
            }
            membroCampanhaMap.get(objectId).add(agr);
        }
        System.debug('MembroCampanhaMap -> ' + MembroCampanhaMap);
        return membroCampanhaMap;
    }

and I have a List<Account> with all the accounts (including the ones that are on the membroCampanhaMap). This account list is passed on the function parameter.

I have to iterate over just the accounts that are on the membroCampanhaMap, so there is a way to like to compare these 2 and maybe create a new one with just the needed Accounts?

so I can do what I need with these records.

By the way, I even tried to Query more fields on the membroCampanhaMap, but when I added Object.LastModifiedDate (for example), it says that is an invalid field, with the ones that are on the select working fine