You need to sign in to do that
Don't have an account?

Getting the parent page
Hi,
I want the user to be redirected to the parent page of the current view when he/she clicks save. So say I have an object Building__c and inside it I have Storage__c. The user clicks on a storage for a building to edit it and after he's done editing he clicks on Save. Now I want him to be redirected to the Building view.
Thanks.
Thanks but the retUrl parameter is already set by default on the edit button (more like edit "link"). So no need for a custom button. e.g. here's the actual link that is referenced by the edit button on the parent page (Building):
https://me.na4.visual.force.com/apex/Storage?id=a0o4000000012NZ&retURL=%2Fa0040000009YoT7&sfdc.override=1
I'm wondering how I can get the redirect URL from this link. Btw I posted here because I'm doing a VF page and I thought there may be some relevance eventho the controller is written in Apex.
Thanks again!
EDIT: Looks like System.currentPageReference().getParameters().get('retURL') will do it!
All Answers
Not really a "Visualforce" question, but to answer the question, you can provide a parameter on a custom button to suggest where the user should return to. For example:
{!URLFOR($action.storage__c.new,null,[retURL="/"&building__c.id],false])}
You can create a custom button and change the standard "edit" button with this custom button. When the user clicks on your custom "edit" button, the additional parameters will be included in the URL. Salesforce will then redirect the user to the appropriate page after saving the record. As an additional caevat, if the field is editable, clicking "save" will redirect the user to the building__c that was referenced before the record was edited, not the building__c that was referenced during the edit.Thanks but the retUrl parameter is already set by default on the edit button (more like edit "link"). So no need for a custom button. e.g. here's the actual link that is referenced by the edit button on the parent page (Building):
https://me.na4.visual.force.com/apex/Storage?id=a0o4000000012NZ&retURL=%2Fa0040000009YoT7&sfdc.override=1
I'm wondering how I can get the redirect URL from this link. Btw I posted here because I'm doing a VF page and I thought there may be some relevance eventho the controller is written in Apex.
Thanks again!
EDIT: Looks like System.currentPageReference().getParameters().get('retURL') will do it!
public PageReference Save() { string retLocation = System.currentPageReference().getParameters().get('retUrl'); PageReference returnto = new PageReference('/' + location); returnto.setRedirect(true); return returnto; }