What's wrong with this code?

public PageReference goodResponse() {
    PageReference fwdMessage = new PageReference(Page.TLResponsePage);
    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?


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'",. – okay56k 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.