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
King KonKing Kon 

Get Nested Map Values

Hi can anyone help,

I have created a map which represents the following

map<Id, Map<Id, SObject> myMap = new map<Id, Map<Id, SObject>();

I have populate the different keys and values but I'm having problems retrieving the values in the SObject without having to loop through the map.

Something like myMap.values().values()

I know I can use mymap.get().get() so there must be some sort of shortcut
Adnubis LLCAdnubis LLC

myMap.values() would return a list of map<Id,SObject>(); List has no method values() so it would fail if you tried to call values again.

myMap.get(ID).get(ID) would return an SObject. 
myMap.get(ID).values() would return a list of SObjects

I don't believe there to be any other shortcuts to help you get around looping unless you have another way to get the keys. 


Elie.RodrigueElie.Rodrigue
When you are populating your data, you could add all of your sObject to another list. This wont have a big impact on heap size as its reference based (only the memory address is stored object is not duplicatied).
Elie.RodrigueElie.Rodrigue
Were you able to solve your issue?