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
vikas rathi91vikas rathi91 

Not able to get the value from map. I am put the value in map using aggregate list.

Hi ,

 I am put the value in map using the Aggregate list  but not abel to get the value from map.
Map<Id,List<Id>> BdrepMap = new Map<id,list<id>>();
List<AggregateResult> opp_line_item_list = [Select OpportunityId, Product_BD_Rep__c, SUM(UnitPrice) FROM OpportunityLineItem 
                                                        WHERE opportunityId IN : oppMap.keyset() GROUP By Product_BD_Rep__c, OpportunityId];
           
for(AggregateResult oli : opp_line_item_list){
                        BdrepMap.put((ID)oli.get('opportunityId'),New list<id>());
                        BdrepMap.get((ID)oli.get('opportunityId')).add((ID)oli.get('Product_BD_Rep__c'));
                  }
//oppteamlist  its another list
 for(opportunityTeamMember team : oppteamlist){
                if(team.UserId != oppMap.get(team.OpportunityId).OwnerId && 
                   team.UserId == BdrepMap.get(team.OpportunityId).Product_BD_Rep__c){
                    deleteOppTeam.add(team);
                } 
            }
// error is Variable does not exist: Product_BD_Rep__c

I am not able to find any solution .
Can any one corret me.

Thanks in advance.
Raj VakatiRaj Vakati
Try like below 
WIll return the BdrepMap.get(team.OpportunityId) the LIST 

 
Map<Id,List<Id>> BdrepMap = new Map<id,list<id>>();
List<AggregateResult> opp_line_item_list = [Select OpportunityId, Product_BD_Rep__c, SUM(UnitPrice) FROM OpportunityLineItem 
                                                        WHERE opportunityId IN : oppMap.keyset() GROUP By Product_BD_Rep__c, OpportunityId];
           
for(AggregateResult oli : opp_line_item_list){
                        BdrepMap.put((ID)oli.get('opportunityId'),New list<id>());
                        BdrepMap.get((ID)oli.get('opportunityId')).add((ID)oli.get('Product_BD_Rep__c'));
                  }
//oppteamlist  its another list
 for(opportunityTeamMember team : oppteamlist){
                if(team.UserId != oppMap.get(team.OpportunityId).OwnerId && 
                   team.UserId == BdrepMap.get(team.OpportunityId)[0]){
                    deleteOppTeam.add(team);
                } 
            }
// error is Variable does not exist: Product_BD_Rep__c

 
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi accky,

BdrepMap.get(team.OpportunityId) will return list of id's . You cannot query a field from it.

Rather if you have only one 'Product_BD_Rep__c' for an opportunity then you can use Map<id,Opportunity> and can extract values as you did before : BdrepMap.get(team.OpportunityId).Product_BD_Rep__c value .

Thanks.