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

1 Answer 1


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.

  • 1
    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 Jun 12, 2014 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. Jun 12, 2014 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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