3

What's wrong with this code?

public PageReference goodResponse() {
    PageReference fwdMessage = new PageReference(Page.TLResponsePage);
    fwdMessage.setRedirect(true);
    return fwdMessage;
}

The TLResponsePage is there and everything. I'm calling this method from another method that returns another PageReference. Should all be good, but instead I get this error:

Constructor not defined: [System.PageReference].<Constructor>(System.PageReference)

Any ideas?

3

Just change your declaration to:

PageReference redirect = Page.MyPage;

You can't pass a PageReference into the PageReference constructor, which you are trying to do.

  • So simple. Thank-you. And if I have some global variables in that method's class, should I be able to refer to them in TLResponsePage by their name? Because that returns this error: "Unknown property 'ParentClass.varName'",. – cd-rum Jan 28 '16 at 4:26
  • 1
    I'm not sure what you're getting at. Maybe worth a separate question? You can set parameters with redirect.getParameters().put(key, value). – Adrian Larson Jan 28 '16 at 4:32

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.