I have a visual force page using an extension and the standard controller. I added a pagereference save() action to the page but it is only updating the child and grandchild records. How can I get this save button to update the standard controller as well as the child and grandchild records? Also, how can the page go to the standard controller's record after saving? I am new to apex so if you could add an explanation as to what is wrong and why your answer will work that would be perfect. I am trying to understand the system. Thank you in advance!
Extension
public with sharing class myClass {
private final Parent__c SiteP;
public List<Child__c> childList {get; set;}
public List<GrandChild__c> grandchildList {get; set;}
public myClass (ApexPages.StandardController stdController)
{ SiteP = [SELECT Id, Name,Status__c FROM Parent__c
WHERE Id =
:ApexPages.currentPage().getParameters().get('id')];
}
//Public lists here for Child and Grandchild records//
public PageReference saveAll() {
update childlist;
List<GrandChild__c> children = new List<GrandChildren__c>();
for (Child__c c : childList) {
grandchildlist.addAll(c.GrandChild__r);
}
update grandchildlist;
update SiteP;
return apexpages.currentpage();
} }
Visualforce page
<apex:page standardController="Parent__c" extensions="myClass">
<apex:form >
<apex:commandButton value="Save" action="{!saveAll}"/>
//Parent__c section here used from standard controller//
//Child__c code section here used from extension//
//GrandChild__c code section here used from extension//
</apex:form>
</apex:page>