You need to sign in to do that
Don't have an account?
One_Kitchen_Guy
DML Operation on list-as-value map? Please Help
Hi guys,
Im trying to update opportunities in a list in a map and I'm tearing my hair out trying to figure it out.
So my code looks something like this...
The error im getting is:
Can someone please explain how I can update each opportunity in the lists in the map without looping through each list in the map and adding each of the opportunities to another list then updating that new list?
Thank you in advance!!
Im trying to update opportunities in a list in a map and I'm tearing my hair out trying to figure it out.
So my code looks something like this...
Opportunity[] opps = [SELECT Id, Expiration__c, AccountId FROM Opportunity]; Map<Id,Opportunity[]> expiredOppsMap = new Map<Id, Opportunity[]>(); //Some manipulation on the Opportunities in 'opps'... for(Integer i=0; i<opps.size(); i++){ if(expiredOppsMap.ContainsKey(opps[i].AccountId)){ expiredOppsMap.get(opps[i].AccountId).add(opp[i]); }else{ expiredOppsMap.put(opps[i].AccountId, new List<Opportunity>{opps[i]}); } } update expiredOppsMap.values();
The error im getting is:
DML requires SObject or SObject list type: LIST<LIST<Opportunity>>
Can someone please explain how I can update each opportunity in the lists in the map without looping through each list in the map and adding each of the opportunities to another list then updating that new list?
Thank you in advance!!
Ankit Arora
Once you are done with the changes in opps then why you want it to be added in MAP's list? Why you can't directly update it? If there is any other specific requirement which says you have to do like this then you've to loop over lists from map and manupulate the data and then update it.
bob_buzzard
Each map value is a list of opportunities, not a single opportunity, so you are asking to update a list of lists of opportunities, which isn't allowed. You'll need to iterate the values, build a single list and then update them all in one go. Something like :