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
JoeyDJoeyD 

Replacing save behavior

Is it possible to replace only the save behavior of a custom object, without recreating the detail page in visualforce?

We have a custom object that is a child to a parent custom object, and when we create a new child record and save, we'd like to be redirected to the master detail record.

 

So as an example, if you create a new Contact for Account1, and save, you return to the Account1 detail page.

 

I've used methods like the code below in extension classes for visualforce pages, but I don't know how I would use only this single method and have it replace the operation of that object's standard controller.

 

 

public PageReference save() {
    
        try{
            update pfc;
        }
        catch(DmlException ex){
            ApexPages.addMessages(ex);  
        }
        PageReference pr = new PageReference('/home/home.jsp');
        pr.setRedirect(true);
        return pr;
    }
           

 

 

 

I hope I'm making sense!

 

Any help would be greatly appreciated.

hisrinuhisrinu

You can't redirect from trigger to any of the page.

 

However in your case you can redirect to the detail page only if you creates a record from relatedlist.

 

You have to do the below steps.

Create a new button and name it as "New".

Use onclick javascript and change the return url to the detail id rathern than child record id.

 

Only disadvantage is it will not work from the tab.