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
stollmeyerastollmeyera 

How to redirect from one VF page to another on save

I have one VF page for a parent record and a second VF page for the child record.  I would like the two pages to link together on save.  That is, I input values on page1, upon hitting save it saves the values and then redirects me to my second page.  Considering it is a simple redirect, I really don't feel I need to write a controller, correct?

Chamil MadusankaChamil Madusanka

You can use following code;

 

PageReference pageRef = new PageReference('/apex/YourPageName');
pageRef.setRedirect(true);

 But If you want to use same controller class for both pages, setRedirect(false);

Otherwise it will run the constructor.

PageReference pageRef = new PageReference('/apex/YourPageName');
pageRef.setRedirect(false);

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Deepak Kumar ShyoranDeepak Kumar Shyoran

The code suggested by chamill is fine but it might create some exception in case of Managed package or if the org have a namespace so to avoid such exception use the following code.

 


PageReference pageRef = Page.YOUR_PAGE_NAME ; pageRef.setRedirect(true);

//To maintain same wizard by using same controller
PageReference pageRef = Page.YOUR_PAGE_NAME ; pageRef.setRedirect(false);

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.