1

Declaring a map with list as value and getting the output for value as: "common.apex.runtime.impl.ScalarList@7861"

Page:

<apex:page controller="abc123ex">
    <apex:outputPanel >{!retrieve}</apex:outputPanel>
</apex:page>

Controller:

public class abc123ex {
    public map<integer, list<integer>> getRetrieve() {
        map<integer, list<integer>> m = new map<integer, list<integer>>{
            1 => new list<integer>{1,2,3},
            2 => new list<integer>{1,2,3}
        };
        return m;
    }
}

Actual Output:

{1=common.apex.runtime.impl.ScalarList@7861, 2=common.apex.runtime.impl.ScalarList@7861} 

Expected Output:

{1=(1, 2, 3), 2=(1, 2, 3)}

Thanks

10
  • 2
    I am able to run this code no problem through Execute Anonymous.
    – Adrian Larson
    May 28, 2015 at 15:04
  • Interesting, I dont know why I am getting that error. Let me try again. Thanks
    – sf_user
    May 28, 2015 at 15:07
  • Adrian, Can you please run that piece of code on VF page and see if you are able to get the result. Thanks
    – sf_user
    May 28, 2015 at 15:10
  • Are you getting an error or is the output being printed out as you have it shown in your question?
    – BarCotter
    May 28, 2015 at 15:17
  • 1
    Yes. That's what I am trying
    – sf_user
    May 28, 2015 at 15:26

1 Answer 1

3

I do not think Visualforce can "pretty print" Maps the same way it would in the console. You need to create some other way to display the values from the Map.

This code works as expected:

public class abc123ex {
  public String getRetrieve() {
     map<integer, list<integer>> m = new map<integer, list<integer>>{
        1 => new list<integer>{1,2,3},
        2 => new list<integer>{1,2,3}
     };
     return String.valueOf(m);
   }
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .