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
Pradeep Pradhan 21Pradeep Pradhan 21 

Write apex code to store Opportunity records using Map. and display them using foreach loop

PriyaPriya (Salesforce Developers) 
Hi Pradeep,

Here is the sample code :- 
Ma<Id,List<Opportunity>> accountOppMap = new Map<Id,List<Opportunity>>();
for(Opportunity opp : [Select id,accountId from opportunity]){
    List<Opportunity> opplst = AccountOppMap.get(opp.AccountId);
    if(opplst == null)
        opplst = new List<Opportunity>();
    opplst.add(opp);
    accountOppMap.add(opp.accountId,opplst);
}