Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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>
share|improve this question
    
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 baird@leadgreen.org –  Baird Straughan Apr 11 at 21:13
add comment

2 Answers

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);
    }
share|improve this answer
    
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. –  Daniel Hoechst Feb 18 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 Feb 18 at 23:51
    
def. something wrong anyway ;) –  brovasi Feb 19 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? –  Daniel Hoechst Feb 19 at 0:07
    
Yes and I copy/paste exactly your code. Don't get the error anymore ;-) –  brovasi Feb 19 at 0:13
add comment
up vote 5 down vote accepted

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);
    }
}
share|improve this answer
    
Can you try new PageReference('/apex/Case2') then getParameters().put('id', c.Id) and see if it still blows up? –  user320 Feb 22 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. –  Daniel Hoechst Feb 23 at 4:44
1  
Case has been escalated to R&D. –  Daniel Hoechst Feb 25 at 21:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.