Hello Folks
I have a small query regarding Maps in Apex. I have a map map <String, list <Account>>. I am trying to do the following –
What needs to be done: I am passing a key to string variable and then passing that string to a Map.get() method to get the values for that key. Here, it does not give me the right answer. Even when I print out the Map using System.Debug() it prints out the map very differently!
String Id = 'Some Id that is the key in the map';
List <Account> testList = Map.get(Id);
This does not give me the corresponding value and I do not know why!
BUT
when I type the below code, the values are printed out perfectly.
for(String s : Map.keySet()){
List <Account> TestList = Map.get(s);
System.Debug('TestList' + TestList);
}
The Test list actually prints out what it is supposed to print out i.e. for each key it prints out the values where as when I print the map it does not print out as expected.
What is expected: I want to pass a key to the Map.get() method to retrieve the results but its clearly not happening in my case.
Any kinds of help is really appreciated!
The only two things I can think of here are:
As others have already mentioned here, please post the actual code segment so we can help further or close this issue.
Thanks