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
dev401hasdev401has 

Pagereference is not working as expected

I have a standard page on which I have kept a custom button.
On click of custom button it opens a visualforce page in same window. When I fill in the values in that and click on save button then as per my pagereference method it should redirect back to that standard deal page and it does.

But the URL at top does not change and on click of refresh in browser it directs me back to that visualforce page.

Why is URL at top not changing?

 

pageref= new Pagereference ('/' + customobject.Id);
pageref.setRedirect(true);
return pageref;

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Try using StandardController.view() instead:

 

return new ApexPages.StandardController(customobject).view();

You actually don't need to setRedirect manually in this case, because it should automatically work. The obly problem here is that you're still on the Visualforce server instead of the core instance server. Using the StandardController's view method makes sure you're going back to the correct server name.

All Answers

sfdcfoxsfdcfox

Try using StandardController.view() instead:

 

return new ApexPages.StandardController(customobject).view();

You actually don't need to setRedirect manually in this case, because it should automatically work. The obly problem here is that you're still on the Visualforce server instead of the core instance server. Using the StandardController's view method makes sure you're going back to the correct server name.

This was selected as the best answer
Kirill_YunussovKirill_Yunussov

This solution is not working for me.   After going to the new page, the URL on top of the screen is still showing the visual force server/page, and I still have the development view on.

 

My specific case: standard controller on the VF page is Shipping Address (custom object).    From the VF page, once the button is pressed, I want to go to the opportunity record.   I have an opportunity variable in the controller, called "opp".

 

This is the syntax I am using, and which is still producing the same result as "return new PageReference('/' + opp.id)":

 

return new ApexPages.StandardController(opp).view();  

 

Is this not a valid usage?

 

Kirill_YunussovKirill_Yunussov

Here is a thread explaining the issue and solution.   Redirect was not working because Development Mode was turned on.    Should work fine for the end-users.

 

http://boards.developerforce.com/t5/Visualforce-Development/Pagereference-to-change-page-URL-Set-Redirect-true-not-working/td-p/126129