I have a managed package with this issue:
I have a Visualforce PDF page that optionally includes another page at runtime. I use an apex:include which works fine in development unpackaged. Here is the beginning of the Visualforce page including the section where the second page is optionally included:
<apex:page controller="CustomerInvoiceBatchController" showHeader="false" sidebar="false" applyHtmlTag="false" applyBodyTag="false"
title="{!$Label.CustomerInvoice}" renderAs="pdf" language="{!languageCode}">
<html>
<body style="font-family:Arial, Helvetica, sans-serif;font-size:12px">
<apex:stylesheet value="{!$Resource.RevenovaCSS}"/>
<!----------------------------------- OPTIONAL SUMMARY PAGE ------------------------------------>
<!---------------------------------------------------------------------------------------------->
<apex:outputPanel id="summaryPanel1" rendered="{!AND(isOneCustomer,showCustomHeaderPage)}">
<apex:include pageName="{!customHeaderPageName}"/>
</apex:outputPanel>
Here is the controller method that returns the dynamically included page name:
// "HeaderDummy" means no override - you must supply a page to apex:include tag even if not rendered!
public String getCustomHeaderPageName() {
try {
if(m_tmsDocumentOptions == null) {
initTDO();
}
return m_tmsDocumentOptions.Custom_Header_Page_Name__c != null ? m_tmsDocumentOptions.Custom_Header_Page_Name__c : 'HeaderDummy';
}
catch(Exception e) {
handleException(e,null);
return 'HeaderDummy';
}
}
This all works fine when unpackaged. However, when I package the code it fails when attempting to generate the composite Visualforce page. It fails when trying to get the content of the composite page here in the controller that tries to render and save the PDF:
Blob b = Test.isRunningTest() ? d.getTestContent() : p.getContent();
The error is very unhelpful:
common.apex.runtime.impl.ExecutionException: Exception common.request.servlet.PageDispatcher$Hack404
To summarize: A dynamically-rendered include with a runtime page name works when unpackaged, but fails when packaged. The dynamically-included second page is always a non-packaged custom page.
Here is the included page:
<apex:page renderAs="pdf">
TEST PAGE
</apex:page>
Ideas? Thanks!
PageReference
constructor (assuming that's the way you are doing this)? I have a nagging feeling you may need to ensure the unpackaged page name is prefixed with "c__" and it would help to know how you are constructing the page reference and what sort of value you pass to it. Please add via edit.