I am trying to use Apex to control which component to show inside a <apex:dynamicComponent> but I don't want to hardcode the component names. So my question is, how can I reference the component by name dynamically in Apex? Is there a map/list somewhere that returns all components that I can then iterate over?


After exhaustively searching around this topic I finally found what appears to be the answer:

Loading a custom component into a Visualforce page dynamically

Dynamic components on a Visualforce page

P.S. I have been searching using variations of "dynamic visualforce" as keywords but none had returned the above thread. In fact it wasn't only after I googled for "ApexPages.Component abstract class" that I saw it!


You could query the ApexComponent object. This will give you all VF components available.

I would suggest some sort of naming convention for the ones you would like to have available for dynamic use. This way you can separate them from other VF components

  • Do you know if I can get an instance of the component as well? – Mossi Dec 30 '15 at 21:25

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.