I am currently working on a Lightning Component. Within my Apex Controller I have a nested map looking like this:
Map<LineItem, Map<LineItem, Map<LineItem, Map<String, LineItem>>>> resultMap = new Map<LineItem, Map<LineItem, Map<LineItem, Map<String, LineItem>>>>();
I am able to populate the map within apex, but when I open up console.log(response.getReturnValue());
in my JavaScript Controller the console only displays LineItemController$LineItem
.
I have tried different approaches found on StackExchange, unfortunately I wasn't successful. Anybody has an idea how I can display all of the key/value pairs in the nested map?
Here is some example code:
APEX Controller:
public class LineItemController {
// Quick Method for creating the map
@AuraEnabled
public static Map<LineItem, Map<LineItem, Map<LineItem, Map<String, LineItem>>>> testNestedMap() {
Map<LineItem, Map<LineItem, Map<LineItem, Map<String, LineItem>>>> resultMap = new Map<LineItem, Map<LineItem, Map<LineItem, Map<String, LineItem>>>>();
List<LineItem> lineItemList = new List<LineItem>();
List<LineItem> lineItemList2 = new List<LineItem>();
List<LineItem> lineItemList3 = new List<LineItem>();
List<LineItem> lineItemList4 = new List<LineItem>();
lineItemList = createLineItem(1);
lineItemList2 = createLineItem(10);
lineItemList3 = createLineItem(100);
lineItemList4 = createLineItem(100000);
for (LineItem li : lineItemList) {
resultMap.put(li, new Map<LineItem, Map<LineItem, Map<String, LineItem>>>());
for (LineItem li2 : lineItemList2) {
resultMap.get(li).put(li2, new Map<LineItem, Map<String, LineItem>>());
for (LineItem li3 : lineItemList3) {
resultMap.get(li).get(li2).put(li3, new Map<String, LineItem>());
for (LineItem li4 : lineItemList4) {
resultMap.get(li).get(li2).get(li3).put(li4.code, li4);
}
}
}
}
system.debug(resultMap);
return resultMap;
}
private static List<LineItem> createLineItem(Integer j) {
List<LineItem> lineItemList = new List<LineItem>();
for(Integer i=1; i < 4; i++) {
LineItem li = new LineItem();
li.amount=100.0 * Integer.valueof((Math.random() * 10));
li.code= String.valueOf(i*j);
li.name='Item ' + (i*j);
li.revenue=100.0 * Integer.valueof((Math.random() * 10));
lineItemList.add(li);
}
return lineItemList;
}
public class LineItem {
public String code {get; set;}
public String name {get; set;}
public Decimal amount {get; set;}
public Decimal revenue {get; set;}
public LineItem() {
this.amount = 0.0;
this.revenue = 0.0;
}
}
}
JavaScript-Controller:
({
doInit : function(component, event, helper) {
var action = component.get("c.testNestedMap");
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
console.log(response.getReturnValue());
} else {
console.log(response.error[0].message);
}
});
$A.enqueueAction(action);
}
})
And last but not least the component:
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:appHostable" access="global" controller="LineItemController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:component>