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:
EditBothAC
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(){
con.save();
update contacts;
PageReference result = ApexPages.currentPage();
result.setRedirect(true);
return result;
}
}
And here's my vf page:
EditBothACPage
<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>
<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:repeat>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:commandButton value="Save" action="{!save}"/>
</apex:form>
</apex:page>
Any help would be greatly appreciated.