22

I think I've stumbled across a bug in Spring 14 that is breaking some of my code that is working in Winter 14.

I have two pages that share the same controller. A button on the first page renders the second page as a PDF and attaches it to the Case. This was working prior to Spring 14, but now I'm getting the following error when I click on the button: "The page you submitted was invalid for your session. Please click Save again to confirm your change. " I believe this error is due to changes in CSRF in Spring '14.

If I change the pages to use different controllers, the problem goes away. This isn't an option since I need to share the view state between the two pages. Data entered on the first page is used by the second page.

Last week, I was able to deactivate a critical update and get it working again, but that critical update (Enable CSRF protection on GET and POST requests) is no longer visible in my list of critical updates in my sandboxes. The sandboxes I deactivated it in work, but the ones I didn't deactivate it in don't work.

Can anyone else replicate? Does anyone have a solution or work around?

Here are the pages and classes to replicate:

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 page = new PageReference('/apex/Case2?id=' + c.Id);
        att.Body = page.getContentAsPDF();
        insert att;
        return new PageReference('/' + att.Id);
    }
}

Case1 Page:

<apex:page standardController="Case" extensions="CaseExtension">
    <apex:form id="theForm">
        <apex:pageBlock >
            <apex:pageBlockSection title="Page 1">
                <apex:inputField value="{!Case.Description}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!nextPage}" value="Build PDF"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Case2 Page:

<apex:page standardController="Case" extensions="CaseExtension">
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:outputText value="{!Case.Description}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
</apex:page>
1
  • I have the same problem. Using one controller, a page lists Thank-You Page templates. clicking on a template uses pageReference to render a thank-you page in .pdf and then attaches the body of the pdf to the Opportunity as an Attachment. Salesforce support mistakenly identified hte problem as a Cross-Site Reference Forgery issue, and I've been chasing down that rabbit-hole for a couple hours. I will try the reprogramming; however, I'd prefer that Salesforce just fixed the glitch so that my old code worked, as I have 28 other instances running the same code. Baird Straughan [email protected] Commented Apr 11, 2014 at 21:13

2 Answers 2

8

I was able to replicate this issue, very interesting one. I'm not too sure why exactly you are getting this error. However you should save your case in your controller before to call your second page, that works for me :

public PageReference nextPage() {
        update c;
        Attachment att = New Attachment(Name = 'Test.pdf');
        att.parentId = c.Id;
        PageReference page = new PageReference('/apex/Case2?id=' + c.Id);
        att.Body = page.getContentAsPDF();
        insert att;
        return new PageReference('/' + att.Id);
    }
5
  • Thanks, I don't really want to do an update at that point, but good to know it is an option. I've opened a case with Salesforce developer support. Maybe they'll have an answer. Commented Feb 18, 2014 at 23:38
  • 1
    I understand you don't want to save you record. The problem is the inputfield, I just made another test. Replace the inputfield by a inputTextArea/inputText and it works (without the saving)
    – brovasi
    Commented Feb 18, 2014 at 23:51
  • def. something wrong anyway ;)
    – brovasi
    Commented Feb 19, 2014 at 0:02
  • I'm still not getting to work. I tried changing the inputfield to an inputtextarea, but I get the same message. All you did was change that one tag? Commented Feb 19, 2014 at 0:07
  • Yes and I copy/paste exactly your code. Don't get the error anymore ;-)
    – brovasi
    Commented Feb 19, 2014 at 0:13
6

Salesforce R&D have confirmed this is a regression bug in Spring 14. It is now on the known issues site.

It looks like the problem is with declaring the pagereference instead of doing the better way and using Page.Case2. When I change the controller as below, it works. I have a case open with developer support. Maybe they will tell me why this is.

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;
        att.Body = Page.Case2.getContentAsPDF();
        insert att;
        return new PageReference('/' + att.Id);
    }
}
4
  • Can you try new PageReference('/apex/Case2') then getParameters().put('id', c.Id) and see if it still blows up? Commented Feb 22, 2014 at 3:41
  • 1
    Nope it doesn't work. I have to use Page.Case2 and then I can put parameters on the page before I getContentAsPDF. My case has been escalated to tier 3 developer support. Fingers crossed. Commented Feb 23, 2014 at 4:44
  • 1
    Case has been escalated to R&D. Commented Feb 25, 2014 at 21:27
  • Any solutions? Any updates from R&D? Commented Mar 4, 2016 at 11:11

You must log in to answer this question.

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