1

Can anyone help please? For some reason, the save method (from controller extension) does not work on one VF page that I created, but works on the other.

Heres' the extension class:

public class IVExtension {
public Interview__c i { get; set; }
public List<Interview_Questions__c> q{ get; set; }

public ApexPages.StandardController sc;
public IVExtension(ApexPages.StandardController sc) {
    i = (Interview__c)sc.getRecord();
    q = [SELECT Interview_Parameter__c,Parameter__c,id,ECA_Rating__c,Response_Notes__c,Question__c FROM Interview_Questions__c WHERE Interview_Questions__c.Interview__c =:sc.getId()  ORDER BY Parameter__c DESC ];
}

public PageReference saveRecord() {
update i.Interview_Questions__r;
update i;
return null;
}
}

Here's the VF where it works:

<apex:page standardController="Interview__c" extensions="IVExtension" sidebar="false" >
   <apex:form >
      <div align="center"> <apex:commandButton action="{!saverecord}" value="Save" /> </div>
   <apex:pageBlock mode="maindetail" >
    
                <apex:pageBlockSection columns="4">
        <apex:pageBlockSectionItem dataStyle="width:25%;text-align:center;background-color:#0E2D46;color:white;padding:7px">
            <apex:outputText > <b> Parameter </b></apex:outputText> </apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem dataStyle="width:10%;text-align:center;background-color:#0E2D46;color:white;padding:7px" > <apex:outputText > <b>Question</b> </apex:outputText>
            </apex:pageBlockSectionItem> 
       <apex:pageBlockSectionItem dataStyle="width:35%;text-align:center;background-color:#0E2D46;color:white;padding:7px" > <apex:outputText > <b>ECA Rating</b> </apex:outputText>
            </apex:pageBlockSectionItem>
       <apex:pageBlockSectionItem dataStyle="text-align:center;background-color:#0E2D46;color:white;padding:7px">
            <apex:outputText > <b>Response / Notes</b> </apex:outputText>
       </apex:pageBlockSectionItem>
       
                <apex:repeat value="{!Interview__c.Interview_Questions__r}" var="ques" >
                       <apex:pageBlockSectionItem dataStyle="width:10%;padding:7px;background-color:#0E2D46;color:white">
                               <apex:inputField value="{!ques.Parameter__c}"/> </apex:pageBlockSectionItem>
                       <apex:pageBlockSectionItem dataStyle="width:30%;padding:7px;background-color:#0E2D46;color:white">
                               <apex:outputField value="{!ques.Question__c}" style=""/></apex:pageBlockSectionItem>
                       <apex:pageBlockSectionItem dataStyle="width:5%;padding:7px">
                               <apex:inputField value="{!ques.ECA_Rating__c}"/> </apex:pageBlockSectionItem>
                       <apex:pageBlockSectionItem dataStyle="width:55%;padding:7px">
                               <apex:inputField value="{!ques.Response_Notes__c}"/> </apex:pageBlockSectionItem>
                </apex:repeat>
                </apex:pageBlockSection>
   </apex:pageBlock>
   <div align="center"> <apex:commandButton action="{!saverecord}" value="Save" /> </div>
   </apex:form>
</apex:page>

Here's where the save button does not work. The value does not get retained.

<apex:page standardController="Interview__c" extensions="IVExtension" sidebar="false" >
<apex:form >

<apex:pageBlock>
      <div align="center"> <apex:commandButton action="{!saveRecord}" value="Save" /> </div>

<apex:pageBlockTable value="{!q}" var="ques"  >
<apex:column headerValue="Parameter"> <apex:inputField value="{!ques.Parameter__c}"/> </apex:column> 
<apex:column value="{!ques.Question__c}" /> 
<apex:column headerValue="ECA Rating"> <apex:inputField value="{!ques.ECA_Rating__c}"/> </apex:column> 
<apex:column headerValue="Response/Notes"> <apex:inputField value="{!ques.Response_Notes__c}"/> </apex:column> 
</apex:pageblocktable>
      <div align="center"> <apex:commandButton action="{!saveRecord}" value="Save" /> </div>

   </apex:pageBlock>

   </apex:form>
</apex:page>

Thanks

1 Answer 1

3

Your code updates the list of child records from the parent record:

update i.Interview_Questions__r;

But you're editing q:

<apex:pageBlockTable value="{!q}" var="ques"  >

Instead, you'd want to change your code to use the child related list:

<apex:pageBlockTable value="{!Interview__c.Interview_Questions__r}" var="ques"  >

You don't need q at all; the controller will automatically query the records for you.

1
  • Thank you @sfdcfox! You might be able to tell I'm quite new to coding, so I really appreciate the help.
    – user90529
    Commented Mar 5, 2021 at 0:42

You must log in to answer this question.