Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So at the moment I have a VisualForce Page that uses the following code:

<apex:page standardController="Contact" extensions="RelationshipTreeController">
    <apex:repeat value="{!nameToRelationType}" var="name">
        <apex:repeat value="{!nameToRelationType[name]}" var="relationType">
            <apex:outputText value="{!name} ({!relationType})"/>

And an extension controller with a Map<String, List<String>> nameToRelationType. The constructor will populate the map and the VF page lists the contents of the map using the nested <apex:repeats

What I would prefer though is to take those keys and just make a List<String> with them. Then the first repeat in the VF page will iterate through that List and within there it will call a function passing in the current String from the List and the function will create the List<String> that would have been the value in the map and return it. Sadly though I cannot call a function with a paramter using <apex:repeat and I cannot use the <apex:param since it cannot be a child of <apex:repeat. So does anyone have any insight? I am pretty new to Salesforce

share|improve this question
up vote 6 down vote accepted

What you are looking to do is not possible. From what I understand, basically you would prefer to do something like this:

<apex:repeat value="{!keyList}" var="key">
    <apex:repeat value="{!functionToGenerateList(key)}" var="val">
        // do some stuff related to the val

Unfortunately, this isn't possible since you can not pass parameters back to Visualforce like that.

The way you are currently doing this is what I would consider best practice. It may feel a bit weird, but if you are new to Salesforce development, you will quickly learn to get really familiar with Map. It is utilized heavily. There is some documentation on working with them in Visualforce, but you are already doing it properly.

share|improve this answer
Thanks! It didn't feel weird necessarily since it worked perfectly. I was just hoping to optimize and get rid of the overhead of the map by using the function. Good to know though – Louis Pujol Jun 12 '14 at 14:17
I know exactly what you mean @LouisPujol. I have gone through that same process before for this where I tried to clean it up a bit, and it felt odd that what I did was kind of the best way to do it. – Jesse Altman Jun 12 '14 at 14:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.