Spring 14 regression- getContentAsPDF() not working with PageReference(‘partialURL’)
Apex , VisualForce , Spring 14
Last updated 2015-05-15 ·Reference W-2071952 ·Reported By 30 users
Summary
Starting with Spring 14 -getContentAsPDF() is throwing error- “The page you submitted was invalid for your session. Please click Save again to confirm your change.” when used with PageReference(‘partialURL’). The workaround is to use Page.existingPageName.
Repro
Setup requirements
=====================
create follwoing VF pages and controller
Visualforce Page- case3
=======================
<apex:page standardController="Case" extensions="CaseExtension" showHeader="false">
<apex:form id="theForm">
<apex:pageBlock >
<apex:pageBlockSection title="Page 1">
<apex:inputTextarea value="{!Case.Description}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!nextPage}" value="Build PDF"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Visualforce Page- case2
=======================
<apex:page standardController="Case" extensions="CaseExtension" showHeader="false" >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputText value="{!Case.Description}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Controller-
=================
public class CaseExtension{
public Case c;
public CaseExtension(ApexPages.StandardController stdController) {
c = (Case)stdController.getRecord();
}
public PageReference nextPage() {
Attachment att = New Attachment(Name = 'Test.pdf');
att.parentId = c.Id;
PageReference pdf = new PageReference('/apex/Case2?id=' + c.Id);
//PageReference pdf = new PageReference('/apex/Case2?id=' + c.Id); //NOT working
//WORKAROUND
/* PageReference pdf = Page.case2;
pdf.getParameters().put('id',c.Id);*/
att.Body = pdf.getContentAsPDF();
insert att;
system.debug('attachment inserted');
return new PageReference('/' + att.Id);
}
}
Steps to Reproduce (Spring 14)
1. Login as any User
2. Navigate to the following link - <salesforce instance>/apex/case1?id=<caseid>
3. Click on 'Build PDF' button.
4. You get error- “The page you submitted was invalid for your session. Please click Save again to confirm your change.”
5. change the controller -
Comment out line 12 and uncomment line 15 and 16 and test again
6. It works fine
Workaround
Workaround
-Using Page.existingPageName instead of PageReference ('partialURL'). (As mentioned in steps to replicate )
The documentation also mentions in PageReference to use Page.existingPageName
“This syntax is less preferable for referencing other Visualforce pages than Page.existingPageName because the PageReference is constructed at runtime, rather than referenced at compile time. Runtime references are not available to the referential integrity system. Consequently, the platform doesn't recognize that this controller or controller extension is dependent on the existence of the specified page and won't issue an error message to prevent user deletion of the page.”
Reported By (30)















Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.