3

This question already has an answer here:

I receive this error:

Incorrect parameter type for subscript. Expected Number, received Text

when I try to access the size of a List like this:

<apex:outputText value="{!accountsMap[key].size}" />

with a Map declared in the controller like this:

public Map<Id, Account[]> accountsMap {get; set;}

Does this just not work or am I missing something?

marked as duplicate by Sergej Utko, Mike Chale, Peter Knolle, eyescream, Andrew Fawcett Dec 13 '13 at 20:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What's your variable name? In VF you access map but in Apex you've shown us accountsMap... If the key is of type Id VF shouldn't try to think about it as a number field... – eyescream Dec 13 '13 at 18:30
  • Is that a typo in the question? you said "the size of a List", but your code has a Map, not a List – Sem0 Dec 13 '13 at 19:06
  • Sorry; forgot to change map to accountsMap in the markup. – kulishch Dec 13 '13 at 19:59
  • @Sem0 the value for the matching key is a List. – kulishch Dec 13 '13 at 20:01
  • 1
    This is a dupe based on the link @mast0r submitted. It's just not possible to do it in a VisualForce page. – kulishch Dec 13 '13 at 20:14