• Ben_Burkle
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I'd like to have a VisualForce page that allows editing fields from both a master record and its associated detail records.  I'm close, but it doesn't seem to save the changes to the detail records.

 

It makes sense to me that the standardController for the master record would not update all the detail records, so I've tried updating the detail records in a controller extension.  It doesn't seem to work.

 

Can someone please tell me if I've gone off course and where? 

 

 

<apex:page standardController="Master__c" extensions="masterExtension" tabstyle="Master__c" sidebar="false" > <apex:form > <apex:pageBlock mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:inputField value="{!Master__c.name}"/> <apex:pageBlockTable value="{!Master__c.Detail__r}" var="detail"> <apex:column value="{!detail.name}"/> <apex:column headerValue="Detail Field"> <apex:inputField value="{!detail.detail_field__c}"/> </apex:column> more columns here </apex:pageBlockTable> </apex:pageBlock></apex:pageBlock>

 

 

public class masterExtension { private final Master__c master; private final ApexPages.standardController theController; public masterExtension(ApexPages.StandardController stdController) { this.master = (Master__c)stdController.getRecord(); theController = stdController; //I'm guessing here. I received a Null Pointer Exception without it } public PageReference save() { List<Detail__c> addDetails = [Select ID from Detail__c Where Detail__c.Master_Field__c = :master.ID]; update addDetails; return theController.save(); }}

 

.  

 

 

 

 

 

I'd like to have a VisualForce page that allows editing fields from both a master record and its associated detail records.  I'm close, but it doesn't seem to save the changes to the detail records.

 

It makes sense to me that the standardController for the master record would not update all the detail records, so I've tried updating the detail records in a controller extension.  It doesn't seem to work.

 

Can someone please tell me if I've gone off course and where? 

 

 

<apex:page standardController="Master__c" extensions="masterExtension" tabstyle="Master__c" sidebar="false" > <apex:form > <apex:pageBlock mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:inputField value="{!Master__c.name}"/> <apex:pageBlockTable value="{!Master__c.Detail__r}" var="detail"> <apex:column value="{!detail.name}"/> <apex:column headerValue="Detail Field"> <apex:inputField value="{!detail.detail_field__c}"/> </apex:column> more columns here </apex:pageBlockTable> </apex:pageBlock></apex:pageBlock>

 

 

public class masterExtension { private final Master__c master; private final ApexPages.standardController theController; public masterExtension(ApexPages.StandardController stdController) { this.master = (Master__c)stdController.getRecord(); theController = stdController; //I'm guessing here. I received a Null Pointer Exception without it } public PageReference save() { List<Detail__c> addDetails = [Select ID from Detail__c Where Detail__c.Master_Field__c = :master.ID]; update addDetails; return theController.save(); }}

 

.