+ Start a Discussion
kiran punurukiran punuru 

How to create a map of opportunity ownerid against List of Opportunity

How can i create a map of opportunity owner id against list of opportunities for a particular owner id.

Thanks 
Kiran
RatanRatan
try this code
 
map<Id, List<Opportunity>> mapOwnerIdTolstOpp = new map<Id, List<Opportunity>>();

for(Opportunity objOpp: [SELECT Id, Name, OwnerId FROM Opportunity])
{
	if(!mapOwnerIdTolstOpp.containsKey(objOpp.OwnerId))
	{
		mapOwnerIdTolstOpp.put(objOpp.OwnerId, new List<Opportunity>{objOpp});
	}
	else
	{
		mapOwnerIdTolstOpp.get(objOpp.OwnerId).add(objOpp);
	}
}

system.debug('======mapOwnerIdTolstOpp===='+mapOwnerIdTolstOpp);