You need to sign in to do that
Don't have an account?
jucuzoglu
How do I redirect the user after an Update?
I have created a VisualForce page which allows an object record to be updated.
I utilized site to display the page, the user can go in edit fields and Save which updates the page.
The problem is that after the user updates the page it is defaulting to mysite.force.com/siteName/SalesforceID
When an update occurs I would like to send my user to a thankyou page. How do I intercept the URL it is going to send the user to and redirect that user instead somewhere else?
I'm assuming that you have an Apex controller/extension tied to your VF page that has a 'save' method that gets invoked when the user hits 'Save' on the page. If so, you can do something like this in the 'save' method:
public PageReference save()
{
//logic to save your data
PageReference p = Page.ThankYou;
//This assumes that your thank you page is also a custom VF page. If not, then you can do something like PageReference p = new PageReference('your Thank you page URL');
p.setRedirect(true);
return p;
}
All Answers
I'm assuming that you have an Apex controller/extension tied to your VF page that has a 'save' method that gets invoked when the user hits 'Save' on the page. If so, you can do something like this in the 'save' method:
public PageReference save()
{
//logic to save your data
PageReference p = Page.ThankYou;
//This assumes that your thank you page is also a custom VF page. If not, then you can do something like PageReference p = new PageReference('your Thank you page URL');
p.setRedirect(true);
return p;
}
I am using the standard controller. Is there an example you could provide or point me to that more or less extends the controller in a manner that would allow me to employ your code solution.
You will need to create a controller extension class, associate it with you VF page and then override the standard 'save' method in the controller extension with the code that I had posted earlier. More details on controller extensions can be found here - http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm.
Hope this helps....
Here is what I have, the code is running (because I see the field updating) but the redirect does not seem to be happening. Any idea what I might be doing wrong?
Is the commandButton on the VF page tied to the 'saveAndRedirect' method (and not 'save')? It should look something like:
Its very similar but there is a difference. Do you think it is causing the issue?
No - that looks correct. What happens after the user hits 'Update'? Are they still being redirected to the record detail page? Or do they remain on the existing VF page?
Also, can you check in your Debug Logs to make absolutely sure that the 'www.google.com PageReference code is being invoked? Perhaps you can put a couple of System.debug statements to be absolutely sure.
They end up at the object page so like s6.salesforce.com/(objectID)
I figured out why the redirect was not working, something was erroring out in my code. I think my issue is one of scope.
See the page below
I need to figure out how to access the cu object fields in the Save method and the proper syntax to perform the Save logic. The code I was using before was breaking which is why it appeared to not be re-directing.