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
guest1231231guest1231231 

Getting Id value from a Map List Collection

How do I get the Opportunity Id value from the list collection in the map OppsMap?

 

List<Account> Accts = new List<Account>{};
Accts = [select Id, First_Contact_Date__c, (select Id from Opportunities) from Account];

Map<Id, List<Opportunity>> OppsMap = new Map<Id, List<Opportunity>>{};
for(Account a: Accts) {
OppsMap.put(a.Id, a.Opportunities);
}

-Thanks

 

Anand@SAASAnand@SAAS

Not knowing exactly what you are trying to do here's some code to get your started in the right direction:

 

 

List<Account> Accts = new List<Account>{};
Accts = [select Id, First_Contact_Date__c, (select Id from Opportunities) from Account];

Map<Id,  List<Opportunity>> OppsMap = new Map<Id, List<Opportunity>>{};
  for(Account a: Accts) {
    OppsMap.put(a.Id, a.Opportunities);
}

for(List<Opportunity> opptyList:oppsMap.values()){
  for(Opportunity oppty:opptyList){
    system.debug(oppty.Id);
  }
}

 Nested "for" loops might run into issues with Governor limits depending on what you do inside the innner for loop.