+ Start a Discussion
Anup Kabra 2Anup Kabra 2 

How to come back to Parent object once child record is created using related list.

I am using inline visualforce page in Lightning account detail page as a related list of custom object. When I click on create a new record from VF page, I wan't to come back to parent page that is Account page once a record is created in custom object. How do I achive this. As of now, once the record is created in custom object, I am still in custom object.
NagendraNagendra (Salesforce Developers) 
Hi Anup,

There are a variety of ways of doing what you're asking about. Which to do depends on whether you want to try and use URL hacking. Most hacks have disappeared and definitely won't work with lightning pages. The alternative is to create a controller extension. In most cases, the essence of what you want to do is set redirect = true and direct the page you're linking to, to return to the record you're currently at bypassing the current record's Id and redirecting the page to return to that record Id upon saving.

You can easily do that type of thing in a controller extension by passing the info to the extension, save the record, and return directly to your existing page; provided your extension has the functionality to save your record and generate the redirect PageReference. Here are links to two posts that describe how to do that: Create save button on custom visualforce page to redirect to parent record detail https://salesforce.stackexchange.com/questions/87885/create-save-button-on-custom-visualforce-page-to-redirect-to-parent-record-detai and Redirecting back to original page using visualforce https://salesforce.stackexchange.com/questions/3907/redirecting-back-to-original-page-using-visualforce?rq=1. The latter post also has an answer showing how to do it using javascript.

Override a standard "New" button to redirect to a VF page https://salesforce.stackexchange.com/questions/19066/override-a-standard-new-button-to-redirect-to-a-vf-page?rq=1 by @SFDCFox explains how to use the nooverride parameter with URLFOR to get back to a normal page. In your case, I believe you'd want to try using nooverride = false. I hope you find his post helpful and enlightening.

Please let us know if this helps.

Kindly mark this as solved if the information was helpful.

Thanks,
Nagendra
Anup Kabra 2Anup Kabra 2
Hi Nagendra, thank you for this great info. However, I need little more information on what I am doing now.

1) I am using a inline visualforce page as a related list(custom object) in Account..
2) I am using a URLFOR option to create a new record in custom object via related list.
   <apex:commandbutton action="{!URLFOR($Action.object__c.New)}" title="New Relation" value="New Relation"/>   

How do I proceed from here? I have written a controller for this VF page but it does other functionality.