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

Does there exist a dynamic binding mechanism for the list attribute in the <apex:relatedList> element? I want to display a related list for a relationship that does not exist on all orgs where my managed package is installed.

I found out that this can be implemented with Dynamic Vf components but I want to be sure that there is no easier solution for this?

If dynamic components are the way to go? Does there exits an elegant (=short) example in the web?

share|improve this question
up vote 6 down vote accepted

Indeed Visualforce reports the List attribute as only supporting Literal values. Fortunately it is indeed possible to achieve what you want via Dynamic Visualforce. I found an example of this in the Salesforce Visualforce Developers guide here. In the code sample you can see the RelatedList component being created and the List attribute being set dynamically.

public Component.Apex.OutputPanel getClassroomRelatedLists() 
    Component.Apex.OutputPanel dynOutPanel= new Component.Apex.OutputPanel(); 
    for(String id: selectedNames) 
       Component.Apex.RelatedList dynRelList = new Component.Apex.RelatedList();
       dynRelList.list = id;
    return dynOutPanel;
share|improve this answer

You are correct that this will require dynamic VF components. Anything that you would attempt to bind directly to VF markup will attempt to validate against a real schema component. When installing in an org missing the related list, it will fail.

You've probably already seen this blog entry on developerforce:

But I don't know of a lot of other resources on the web besides that for dynamic Visualforce components.

share|improve this answer

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.