function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rishabh Goyal 18Rishabh Goyal 18 

How to access the map of map vlue in lighning components?


Can you please share your collection structure first.

mukesh guptamukesh gupta
Hi Rishabh,

Forr Example You Can use this code :
map<id,map<id,opportunity>> ao = new map<id,map<id,opportunity>>();
map<id,account> ac = new map<id,account>([select id from account]);
for(Opportunity record:[select id,accountid from opportunity where accountid in :ac.keyset()]) {
  if(!ao.containskey(record.accountid)) {
    ao.put(record.accountid,new map<id,opportunity>());

for(Id accountId:ao.keyset()) {
  for(Id oppId:ao.get(accountId).keyset()) {
    // ac.get(accountid) and ao.get(accountid).get(oppid)
    // are account and opportunity, respectively.

If this solution is usefull for you, Please mark as a Best Answer to help others.

Rishabh Goyal 18Rishabh Goyal 18
Thanks Mukesh, for your input but I am looking for how to access this map of map values in lightning components.

Please find here the stucture of my problem- 

public Map<String,Map<String,Decimal>> mapExpDetails{get;set;}

I have created the attribute the in component and assigned the value to this attribute though controller.
        <aura:attribute name="mapexpensedet" type="Map"/>

Now , I want to print all the values of this like -

I have represented it in apex , Can you help me with how can I access it similarly in lightning component?
Do you want to render the whole map data in a table on the lightning component?
Caleb Kuester 27Caleb Kuester 27

The Lightning component has to have:

<aura:attribute name = "yourData" type="Object" default="{}"/>

In this case, yourData will store your map and the values can be accessed in standard Javascript ways after it is set, but with one caveat. Because it's not initialized as a map and because it's essentially blank, before attempting to access your data, error checking with $A.util.isEmpty() is heavily advised.