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
Andrea GelsominoAndrea Gelsomino 

Save and redirect button

Hi everyone,

I would like the user get back to the "father" page when he save a a new record (Master-Details) , at the moment every time it saved a new "child" record it doesnt'  redirect to the previus content, but its redirect to the details page...and it's not really user friendly if we need to insert more data

I read that I could create a custom "New Button" and passing a custom URL for redirect  but i really don't understand how

Thanks
Andrea 

Tavva Sai KrishnaTavva Sai Krishna
Hi Andrea,

I had worked with the same scenario,but for "edit" button not for "new" button. My requirement is when the child record has been updated then it should redirect it to the parent record detail page. I hope the same will works for the " new " button with slight modification. I modified the code as per your requirement such that it will redirect to the object list page while creating the new record.


1.Create a visualforce page and copy the below code
 
<apex:page standardcontroller="Account" extensions="AttachmenteditPageController" action="save">


</apex:page>
Note: You can change use standard/Custom Object, here i assumed account object and the controller name as "AttachmenteditPageController" which you can change as per your needs .

2. create the controller and copy the below Code.
public class AttachmentEditPageController {

    private ApexPages.StandardController sc;

   public Id redirectid { get; set; }

     public AttachmentEditPageController(ApexPages.StandardController controller) {
        sc = controller;
    
    }
    
    public pagereference save (){
    
        sc.save();
        PageReference SrmDetailPage= new PageReference('/'+001);
         return SrmDetailPage;
    }
    
   

}
Note: If you changed the "extensions" name in the page then change the class name according to it.

3. Override the Standard "New" button with the above created the page.

Let me know if you have any queries/face any issues ,


Thanks and Regards,
Sai Krishna Tavva.