I have an issue where I am trying to render a component on a VF page where I don't know if the component exists in the org or not until run time (I am trying to use a dynamic component on the front end). Since I can't assume it exists by default, I can't reference the component like so:

Component.some_namespace.MyComponent myComp = new Component.some_namespace.MyComponent();

as that won't compile.

I can query the component using SOQL and even get its markup, but can I do anything with the VF markup I get? Could I create a wrapper component and inject the markup somehow? I guess like...

Component.c.WrapperComponent wrapComp = new Component.c.WrapperComponent();
wrapComp.vfMarkup = queriedComponent.Markup;

it's frustrating because the queried component is of type ApexComponent (a metadata type) but the dynamic component requires an object of type ApexPages.Component. There's no way I can convert the ApexComponent to a ApexPages.Component, right?

  • I think Type.forName might be the answer, but I can't seem o make it work either.
    – sfdcfox
    Jul 29, 2016 at 18:53
  • @sfdcfox from what I've seen from other questions/answers on SE, Type.forName used to work but Salesforce decided to close that loop hole or something... Jul 29, 2016 at 19:00
  • salesforce.stackexchange.com/questions/50295 is a workaround... requires additional code post-deploy, but it can be done.
    – sfdcfox
    Jul 29, 2016 at 19:15


You must log in to answer this question.

Browse other questions tagged .