0

I am trying to call a VF page from another VF page which use the same controller.

I am getting the error when i click on the command button which calls the pagereference method and redirects to the next VF page

The page you submitted was invalid for your session. Please refresh your page and try again.

Apex Class

public pageReference SaveNext()
    {
        Savepoint sp = Database.setSavepoint();
        Try
        {
            showErr = false;
            update opp;
            update services;
        }
        catch(exception e)
        {
            showErr = true;
            errMsg = e.getmessage();
            Database.rollback(sp);
            return null;
        }
        PageReference prep = Page.WonPrepCustomer; 
        prep.getParameters().put('id',opp.Id); 
        //return new pageReference('/apex/WonPrepCustomer?id='+opp.Id);
        return prep;

    }

VF page (Commandbutton code)

<apex:commandbutton action="{!SaveNext}" value="Next to Customer Prep" styleClass="slds-button slds-button_brand" rerender="errorParent"  />

Looking through all the other posts regarding this issue. Here are things i already tried

  1. Enabled in Session settings

Enable clickjack protection for customer Visualforce pages with standard headers.

Enable clickjack protection for customer Visualforce pages with headers disabled

  1. Added Showheader=true on <apex:page/> tag.

  2. Use Page. instead of partial url.

  3. Issue remains on classic and lightning experience

Is there anything else that i can try?

  • I believe you need to add .setRedirect(true); before redirect to your PageReference this should clear all the data related to the controller, since both of them use the same controller. – Paul Jun 21 '18 at 12:54
  • @Paul You are god!! That resolved it. If you can put this as an answer i can accept it :). Had been breaking my head over it for past hour or so – Prady Jun 21 '18 at 12:57
  • @Paul So does this mean that you cant share data between pages? – Prady Jun 21 '18 at 13:03
  • In VF you cannot really share data between pages, the only thing you could do is use url params to pass values between them so they know what to do. – Paul Jun 21 '18 at 13:16
  • I know you solved it but can you try to remove rerender and then try? – Tushar Sharma Jun 21 '18 at 13:23
4

You should use setRedirect(true) with your PageReference.

Description according to documentation:

SetRedirect() is a method of PageReference class. When a PageReference value is used as a return value for a commandButton or actionFunction method, the setRedirect() value defines whether it is a client-side redirect or a server-side forward. Thus if you use this with true param controller data will be dumped as it will request server meaning everything is reinitialized, using the class constructor if any, all the variables will be dumped etc and if you use the same controller in 2 pages the error was caused by the pre-existing values that were carrying over to the next page since it is using the same controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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