Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

2 Answers 2

up vote 5 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;
       dynOutPanel.childComponents.add(dynRelList);
    }
    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: http://blogs.developerforce.com/developer-relations/2011/05/dynamic-visualforce-components-in-summer-11.html

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

 
discard

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.