We need to get JSON-Data inside of a Managed Package (there in an Aura Component) from Apex-Code residing outside of the Managed Package directly unmanaged on the subscriber org. We do not want the unmanaged code to get seen by the MP, nor do we want it to get sucked into the MP. The MP-Component can work even without the existence of the unmanaged Apex - then it falls back to default values.

So earlier this week, I have submitted a question to know if it is possible to serialize an APEX sub-class outside of a managed package from within a MP dynamically and the answer did not solve the problem because the error "Type cannot be serialized" was still persistent.

We opted for another workaround where we created a VF page with an APEX controller and serialized the class and displayed it plainly to the body. From within the package we called an instance new PageReference('/apex/SubscriberOrgPage') as this question also suggested and call the method getContent().toString() to grab the page content that contains the JSON. Unfortunately we ran into an unknown Visualforce error that is unrelated to the serialization itself. As an example this following VF page is outside the managed package:

<!-- SubscriberOrgPage -->
<apex:page >

and the following APEX class is a used as a controller for an aura component within the managed package.

public class ManagedPackageController {
  @AuraEnabled public String Load() {
    PageReference pageRef = new PageReference('/apex/SubscriberOrgPage'); 
    String pageContent = pageRef.getContent().toString();
    return pageContent;  

The exception points at pageRef.getContent().toString() with a null message and the type of the exception is a VisualforceException. I am not sure why the error has not been specific of the cause but if I try the same scenario with the aura component and the APEX controller being on the subscriber org, it will simply work.

Is there something I have missed or might this be for security reasons that I am unable to access the page content?

  • Is there a reason the managed package must pull, rather than have the data pushed? And is there a reason that the subscriber org code cannot be a top level Apex class that you instantiate and serialize to JSON?
    – Phil W
    Jan 13, 2022 at 16:31
  • 1
    @PhilW Yes there is a reason: the subscriber Org can run completely on its own. As said in the first paragraph: "The MP-Component can work even without the existing of the unmanaged Apex - then it falls back to default values". Replace "can work" with "has to be able to work" without the MP. The MP is totally optional an must have a tolerance for a range of some subscriber org customizations. So the MP must pull. The subscriber org must know nothing about the MP and must be able to run without the MP.
    – Uwe Heim
    Jan 17, 2022 at 11:28
  • 1
    @PhilW this kills too much of flexibility on the subscriber org and would unnecessarily overcomplicate the current lightweight process. And the current process is on the subscriber-orgs since many years. Solid and tested. There is no budget to change and test every subscriber. Some of the exiting orgs will invest in the extension. Others need go with zero changes and zero effort. We thought long an hard about it. Over 200 Orgs are involved. To keep it decoupled is the only approach.
    – Uwe Heim
    Jan 17, 2022 at 11:50
  • 1
    @PhilW the feature behind this is a class-based trigger framework. It routes every trigger through a dispatcher. The configuration was done with apex classes in the beginning. Later we added Custom Settings. So you can turn on and off or switch between different implementations of Apex Triggers purely by Custom Settings. On production orgs without deployment. Realtime. What we want to deliver now is an improved UI to manipulate these Custom Settings. The settings have multiple layers and can override each others. To display the effective final settings, we need the Framework to evaluate one.
    – Uwe Heim
    Jan 17, 2022 at 12:01
  • 1
    @PhilW LWC makes things usually even harder than Aura. But our current approach is: Use a VF page inside an IFRAME of an Aura Compo. The VF page will use window.sendMessage() to pass the JSON up to the Aura Component. In Germany we say a shot through the toe into the eye... hard to believe that Salesforce is making this soo complicated.
    – Uwe Heim
    Jan 20, 2022 at 17:29

1 Answer 1


We were doing something similar and turns out to fix it your Visualforce reference needs to have the "default" namespace ("c"). So this:

PageReference pageRef = new PageReference('/apex/SubscriberOrgPage'); 


PageReference pageRef = new PageReference('/apex/c__SubscriberOrgPage'); 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .