You need to sign in to do that
Don't have an account?
JasonRogers
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?
The error message points to the first line of the method (the declaration of the map).
Code:
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; }
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.
+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.