How can I redirect my page to parent detail page upon updating both parent and child objects? Both records are saving successfully, but everytime I click the save button, it doesn't go back to the master detail record page.

Here's my controller:


public class EditBothAC{

    private ApexPages.StandardController con;
    public List<Contact> contacts {get;set;}

    public EditBothAC(ApexPages.StandardController controller){
        con = controller;

        contacts = [SELECT Id, FirstName, LastName, Email FROM Contact WHERE accountid=:con.getId() ORDER BY FirstName ASC LIMIT 5];


    public PageReference save(){


        update contacts;

        PageReference result = ApexPages.currentPage();
        return result;


And here's my vf page:


<apex:page standardController="Account" extensions="EditBothAC">

    <apex:form >

            <apex:pageBlock title="Account Detail">
                <apex:pageBlockSection title="Account">
                    <apex:inputField value="{!Account.Name}"/>
                    <apex:inputField value="{!Account.Description}"/>
                <apex:pageBlockSection title="Contacts">
                    <apex:repeat value="{!contacts}" var="c">
                        <apex:inputField value="{!c.FirstName}"/>
                        <apex:inputField value="{!c.LastName}"/>
                        <apex:inputField value="{!c.Email}"/>
            <apex:commandButton value="Save" action="{!save}"/>


Any help would be greatly appreciated.

1 Answer 1


returns current page url.

This would get back you to account detail page:

PageReference result = new PageReference('/'+con.getId());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.