+ Start a Discussion

Invalid nested collection type

I am getting an error during compile time that says "Invalid nested collection type".  Here's the code that it's barfing on.  Can anyone help?

private Map<String, List<OpportunityLineItem>> lineItemsByBusinessUnitForOpportunities(List<Opportunity> opps) {
  Map<String, List<OpportunityLineItem>> map = new Map<String, List<OpportunityLineItem>>();
//The error message points to the above line

Set<Id> oppIds = new Map<Id, Opportunity>(opps).keySet(); List<OpportunityLineItem> lineItems = [select id, acv_Impact__c, Product.business_unit__c, Opportunity.license_start_date__c, Opportunity.expirationdate__c from OpportunityLineItem where opportunity in :oppIds]; for(OpportunityLineItem lineItem : lineItems) { if (!map.containsKey(lineItem.product.business_unit__c)) {
map.put(lineItem.product.business_unit__c, new List<OpportunityLineItem>()); } map.get(lineItem.product.business_unit__c).add(lineItem); } return map; }

The error message points to the first line of the method (the declaration of the map).
I found the error...

You apparently cannot use 'map' as a variable name -- a limitation in the Apex parser I think.  When I changed the name of the map to 'itemListsByBusinessUnit' it compiled just fine.

A better error message would have helped.
I know it's been ages, but thanks for posting this, I just ran into the same thing and your post saved me at least a bunch of minutes!

+1 for at least fixing the error message. No idea why Apex doesn't allow a variable called lowercase 'map' - Java has no problem with that.