function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John DaJohn Da 

Difference between commandButton's onClick and action that returns a PageReference

I want to go to a standard page layout (new record edit mode) from clicking on a button in a VF page. I got this to work by using onClick and adding a script in there with the URL of the page I want to go to. Can this be achieved using PageReference (redirect)? Thanks.
Best Answer chosen by John Da
ManojjenaManojjena
Hi John,

Yes you can achieve this by the help of pageReference .

All Answers

ManojjenaManojjena
Hi John,

Yes you can achieve this by the help of pageReference .
This was selected as the best answer
John DaJohn Da

Hi Manoj, 

I tried doing it with this code:

  public Pagereference goToPageB()
  {
      Pagereference pr = new Pagereference('url here');
                pr.setRedirect(true);
          return pr;
  }

But it doesn't seem to work. The page does not go to a different page. I put the same URL in onClick and it works. Do I miss something here?