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?

1 Answer 1

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.

2
  • 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'",.
    – t56k
    Commented Jan 28, 2016 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
    Commented Jan 28, 2016 at 4:32

You must log in to answer this question.

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