You need to sign in to do that
Don't have an account?
How to create a list or map from 2 different lists/map
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
Here's an example of how you can create a new list of accounts that have a Territory2Association record associated with them for one of the specified territories:
If you find this answer helpful, Please mark it as the best answer.