function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt_Matt_ 

Unable to save every field in VF page

I've looked but have failed to find a remedy thus far. Any input is welcome. 

 

I have a page that creates multiple records at once, with buttons that can add or remove rows(new records) to a pageblocktable. This works. All the records save perfectly. 

 

In addition to these rows there are other inputfields that contain information that should be applied to every single new record. The data from these inputfields does not save. All the fields are found under the same object "End_of_Month_Report__c". Below is the VF page. HTML has been added to format the layout.  

 

<apex:page standardController="End_of_Month_Report__c" extensions="ReportEntry" Title="New End of the Month Report">
<h1><b><font size="5" face="Times New Roman">New End of the Month Report</font></b></h1>

    <apex:form title="New End of the Month Report">
     
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}" rerender="table" />
                <apex:commandButton value="Cancel" action="{!cancel}" rerender="table" />
            </apex:pageBlockButtons>
            <apex:pageblocksection title="Data for All Cities in the Region" id="PBS" collapsible="false">
           
            <apex:pageBlockTable value="{!Report}" var="a" id="table">
                <apex:column headerValue="Station [Domicile First] :">
                    <apex:inputField value="{!a.Station_1__c}"/>
                </apex:column> 
                               
                <apex:column headerValue="Fully Staffed?">
                    <apex:inputField value="{!a.Staffing_Station_1__c}"/>
                </apex:column>
                
                <apex:column headerValue="Staffing Comments :">
                    <apex:inputField value="{!a.Staffing_Comments_Station_1__c}"/>
                </apex:column>
                
                <apex:column headerValue="Date of Station Visit :">
                    <apex:inputField value="{!a.Visit_Date_Station_1__c}"/>
                </apex:column>
                
                <apex:column headerValue="Comments Regarding Visit :">
                    <apex:inputField value="{!a.Visit_Comments_Station_1__c}"/>
                </apex:column>
                
            </apex:pageBlockTable>
            </apex:pageblockSection>
            
<table width="54%">
    <tr><td>
    <apex:pageblocksection title="Domicile Specifics" collapsible="false" ID="DomicileSpecifics">
        <apex:panelGrid columns="2" width="50%" id="DomicileSpecificsGrid">
          <apex:outputText ><b>OT Goal</b></apex:outputText>
          <apex:outputText ><b>OT Actual</b></apex:outputText>
            <apex:inputtext value="{!theText}" id="OTGoalInput">
                <apex:actionsupport event="onchange" rerender="table" status="status"/>
            </apex:inputtext>
            <apex:inputField value="{!End_of_Month_Report__c.OT_Actual_Station_1__c}" id="OTActualInput">
                <apex:actionsupport event="onchange" rerender="table" status="status"/>
            </apex:inputfield>
          <apex:outputText ><b>Hours Planned</b></apex:outputText>
          <apex:outputText ><b>Hours Actually Worked</b></apex:outputText>
            <apex:inputField value="{!End_of_Month_Report__c.Hours_Planned_Station_1__c}"/>
            <apex:inputField value="{!End_of_Month_Report__c.Hours_Worked_Station_1__c}"/>
            <apex:outputText ><b>OPs Taken Total </b></apex:outputText>
            <apex:outputText ><b>OP-04 Delays Total </b></apex:outputText>  
            <apex:inputField value="{!End_of_Month_Report__c.OPs_Taken_Station_1__c}"/>
            <apex:inputField value="{!End_of_Month_Report__c.OP_04_Delays_Station_1__c}"/>
        </apex:panelGrid>
    </apex:pageblockSection>
    </td>
        
        <td>
        <apex:pageblocksection title="Customer Interactions" collapsible="false">
        <apex:panelGrid columns="2" width="50%">
            <apex:outputText ><b>Sales Call Comments</b></apex:outputText>
            <apex:outputText ><b>Customer Issues</b></apex:outputText>
            <apex:inputField value="{!End_of_Month_Report__c.Sales_Call_Customer_Comments_1__c}"/>            
            <apex:inputField value="{!End_of_Month_Report__c.Customer_Issue_1__c}"/>
        </apex:panelGrid>
        </apex:pageblockSection>
        </td></tr>
        </table>    
      
    <apex:pageblockButtons location="Top" Title="Add/Remove a City?">
        <div style="text-align:left;font-weight:bold;">
            <apex:commandLink value="Add Another City" action="{!addRow}" rerender="table" immediate="true" />
&nbsp;|&nbsp;&nbsp;
            <apex:commandLink value="Remove City" action="{!removeRow}" rerender="table" immediate="true" />                
        </div>
    </apex:pageblockButtons>  
    </apex:pageBlock>
    </apex:form>
</apex:page>

 Controller.

Public class ReportEntry {

    public List<End_Of_Month_Report__c> Report {get; set;}

    public ReportEntry(ApexPages.StandardController myController) {
        Report = new List<End_Of_Month_Report__c>();
        Report.add(New End_Of_Month_Report__c());
        }
        

    public void addrow() {
        Report.add(new End_Of_Month_Report__c());}
            
    public void removerow(){
        Integer i = Report.size();
        Report.remove(i-1);}
    
    public PageReference save() {
        system.debug('xxxxxxxxxxxxxxxxx'+ Report);
        insert Report;
        PageReference gorecord = new PageReference('/a1N/o');
        gorecord.setRedirect(true);
        return gorecord; }}

 The fields that do not save are between the <table> tags. 

 

Anyone know where I have gone awry?

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Daniel Zeidler (DZ)Daniel Zeidler (DZ)

Unfortunately you are doing several fundamental things wrong and I can't really explain what they are without going into a lot of the underlying detail about visualforce. So I recommend reading through the visualforce documentation sections on controllers, controller extensions and a quick read through the quick start guide.

 

With that said, here’s a potential work around that isn’t very good but should fix your problem.

 

<apex:page standardController="End_of_Month_Report__c" extensions="ReportEntry" Title="New End of the Month Report">
<h1><b><font size="5" face="Times New Roman">New End of the Month Report</font></b></h1>
<apex:form title="New End of the Month Report">

<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" rerender="table" />
<apex:commandButton value="Cancel" action="{!cancel}" rerender="table" />
</apex:pageBlockButtons>
<apex:pageblocksection title="Data for All Cities in the Region" id="PBS" collapsible="false">

<apex:pageBlockTable value="{!Report}" var="a" id="table">
<apex:column headerValue="Station [Domicile First] :">
<apex:inputField value="{!a.Station_1__c}"/>
</apex:column> 

<apex:column headerValue="Fully Staffed?">
<apex:inputField value="{!a.Staffing_Station_1__c}"/>
</apex:column>

<apex:column headerValue="Staffing Comments :">
<apex:inputField value="{!a.Staffing_Comments_Station_1__c}"/>
</apex:column>

<apex:column headerValue="Date of Station Visit :">
<apex:inputField value="{!a.Visit_Date_Station_1__c}"/>
</apex:column>

<apex:column headerValue="Comments Regarding Visit :">
<apex:inputField value="{!a.Visit_Comments_Station_1__c}"/>
</apex:column>

</apex:pageBlockTable>
</apex:pageblockSection>

<table width="54%">
<tr><td>
<apex:pageblocksection title="Domicile Specifics" collapsible="false" ID="DomicileSpecifics">
<apex:panelGrid columns="2" width="50%" id="DomicileSpecificsGrid">
<apex:outputText ><b>OT Goal</b></apex:outputText>
<apex:outputText ><b>OT Actual</b></apex:outputText>
<apex:inputtext value="{!theText}" id="OTGoalInput">
<apex:actionsupport event="onchange" rerender="table" status="status"/>
</apex:inputtext>
<apex:inputField value="{!dummyReport.OT_Actual_Station_1__c}" id="OTActualInput">
<apex:actionsupport event="onchange" rerender="table" status="status"/>
</apex:inputfield>
<apex:outputText ><b>Hours Planned</b></apex:outputText>
<apex:outputText ><b>Hours Actually Worked</b></apex:outputText>
<apex:inputField value="{!dummyReport.Hours_Planned_Station_1__c}"/>
<apex:inputField value="{!dummyReport.Hours_Worked_Station_1__c}"/>
<apex:outputText ><b>OPs Taken Total </b></apex:outputText>
<apex:outputText ><b>OP-04 Delays Total </b></apex:outputText> 
<apex:inputField value="{!dummyReport.OPs_Taken_Station_1__c}"/>
<apex:inputField value="{!dummyReport.OP_04_Delays_Station_1__c}"/>
</apex:panelGrid>
</apex:pageblockSection>
</td>

<td>
<apex:pageblocksection title="Customer Interactions" collapsible="false">
<apex:panelGrid columns="2" width="50%">
<apex:outputText ><b>Sales Call Comments</b></apex:outputText>
<apex:outputText ><b>Customer Issues</b></apex:outputText>
<apex:inputField value="{!dummyReport.Sales_Call_Customer_Comments_1__c}"/> 
<apex:inputField value="{!dummyReport.Customer_Issue_1__c}"/>
</apex:panelGrid>
</apex:pageblockSection>
</td></tr>
</table> 

<apex:pageblockButtons location="Top" Title="Add/Remove a City?">
<div style="text-align:left;font-weight:bold;">
<apex:commandLink value="Add Another City" action="{!addRow}" rerender="table" immediate="true" />
&nbsp;|&nbsp;&nbsp;
<apex:commandLink value="Remove City" action="{!removeRow}" rerender="table" immediate="true" /> 
</div>
</apex:pageblockButtons> 
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

Controller.

Public class ReportEntry {
public End_Of_Month_Report__c dummyReport {get; set;}
public List<End_Of_Month_Report__c> Report {get; set;}
public ReportEntry(ApexPages.StandardController myController) {
dummyReport = new End_Of_Month_Report__c();
Report = new List<End_Of_Month_Report__c>();
Report.add(New End_Of_Month_Report__c());
}
public void addrow() {
Report.add(new End_Of_Month_Report__c());}

public void removerow(){
Integer i = Report.size();
Report.remove(i-1);}

public PageReference save() {
for(End_Of_Month_Report__c r : Report)
{
r.OT_Actual_Station_1__c = dummyReport.OT_Actual_Station_1__c;
r.Hours_Planned_Station_1__c = dummyReport.Hours_Planned_Station_1__c;
r.Hours_Worked_Station_1__c = dummyReport.Hours_Worked_Station_1__c;
r.OPs_Taken_Station_1__c = dummyReport.OPs_Taken_Station_1__c;
r.OP_04_Delays_Station_1__c = dummyReport.OP_04_Delays_Station_1__c;
r.Sales_Call_Customer_Comments_1__c = dummyReport.Sales_Call_Customer_Comments_1__c;
r.Customer_Issue_1__c = dummyReport.Customer_Issue_1__c;
}

system.debug('xxxxxxxxxxxxxxxxx'+ Report);
insert Report;
PageReference gorecord = new PageReference('/a1N/o');
gorecord.setRedirect(true);
return gorecord; }}

 The basic idea is to create a "dummy" sObject, bind the fields in the table to it and then copy it's values to the Reports before saving.

All Answers

Matt_Matt_
A Workaround that I have played with is to add the inputfields into the column table and have them not render, then using the other fields with some action that will copy the data into the columns upon save/ButtonClick/onChange...Thoughts?
Daniel Zeidler (DZ)Daniel Zeidler (DZ)

Unfortunately you are doing several fundamental things wrong and I can't really explain what they are without going into a lot of the underlying detail about visualforce. So I recommend reading through the visualforce documentation sections on controllers, controller extensions and a quick read through the quick start guide.

 

With that said, here’s a potential work around that isn’t very good but should fix your problem.

 

<apex:page standardController="End_of_Month_Report__c" extensions="ReportEntry" Title="New End of the Month Report">
<h1><b><font size="5" face="Times New Roman">New End of the Month Report</font></b></h1>
<apex:form title="New End of the Month Report">

<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" rerender="table" />
<apex:commandButton value="Cancel" action="{!cancel}" rerender="table" />
</apex:pageBlockButtons>
<apex:pageblocksection title="Data for All Cities in the Region" id="PBS" collapsible="false">

<apex:pageBlockTable value="{!Report}" var="a" id="table">
<apex:column headerValue="Station [Domicile First] :">
<apex:inputField value="{!a.Station_1__c}"/>
</apex:column> 

<apex:column headerValue="Fully Staffed?">
<apex:inputField value="{!a.Staffing_Station_1__c}"/>
</apex:column>

<apex:column headerValue="Staffing Comments :">
<apex:inputField value="{!a.Staffing_Comments_Station_1__c}"/>
</apex:column>

<apex:column headerValue="Date of Station Visit :">
<apex:inputField value="{!a.Visit_Date_Station_1__c}"/>
</apex:column>

<apex:column headerValue="Comments Regarding Visit :">
<apex:inputField value="{!a.Visit_Comments_Station_1__c}"/>
</apex:column>

</apex:pageBlockTable>
</apex:pageblockSection>

<table width="54%">
<tr><td>
<apex:pageblocksection title="Domicile Specifics" collapsible="false" ID="DomicileSpecifics">
<apex:panelGrid columns="2" width="50%" id="DomicileSpecificsGrid">
<apex:outputText ><b>OT Goal</b></apex:outputText>
<apex:outputText ><b>OT Actual</b></apex:outputText>
<apex:inputtext value="{!theText}" id="OTGoalInput">
<apex:actionsupport event="onchange" rerender="table" status="status"/>
</apex:inputtext>
<apex:inputField value="{!dummyReport.OT_Actual_Station_1__c}" id="OTActualInput">
<apex:actionsupport event="onchange" rerender="table" status="status"/>
</apex:inputfield>
<apex:outputText ><b>Hours Planned</b></apex:outputText>
<apex:outputText ><b>Hours Actually Worked</b></apex:outputText>
<apex:inputField value="{!dummyReport.Hours_Planned_Station_1__c}"/>
<apex:inputField value="{!dummyReport.Hours_Worked_Station_1__c}"/>
<apex:outputText ><b>OPs Taken Total </b></apex:outputText>
<apex:outputText ><b>OP-04 Delays Total </b></apex:outputText> 
<apex:inputField value="{!dummyReport.OPs_Taken_Station_1__c}"/>
<apex:inputField value="{!dummyReport.OP_04_Delays_Station_1__c}"/>
</apex:panelGrid>
</apex:pageblockSection>
</td>

<td>
<apex:pageblocksection title="Customer Interactions" collapsible="false">
<apex:panelGrid columns="2" width="50%">
<apex:outputText ><b>Sales Call Comments</b></apex:outputText>
<apex:outputText ><b>Customer Issues</b></apex:outputText>
<apex:inputField value="{!dummyReport.Sales_Call_Customer_Comments_1__c}"/> 
<apex:inputField value="{!dummyReport.Customer_Issue_1__c}"/>
</apex:panelGrid>
</apex:pageblockSection>
</td></tr>
</table> 

<apex:pageblockButtons location="Top" Title="Add/Remove a City?">
<div style="text-align:left;font-weight:bold;">
<apex:commandLink value="Add Another City" action="{!addRow}" rerender="table" immediate="true" />
&nbsp;|&nbsp;&nbsp;
<apex:commandLink value="Remove City" action="{!removeRow}" rerender="table" immediate="true" /> 
</div>
</apex:pageblockButtons> 
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

Controller.

Public class ReportEntry {
public End_Of_Month_Report__c dummyReport {get; set;}
public List<End_Of_Month_Report__c> Report {get; set;}
public ReportEntry(ApexPages.StandardController myController) {
dummyReport = new End_Of_Month_Report__c();
Report = new List<End_Of_Month_Report__c>();
Report.add(New End_Of_Month_Report__c());
}
public void addrow() {
Report.add(new End_Of_Month_Report__c());}

public void removerow(){
Integer i = Report.size();
Report.remove(i-1);}

public PageReference save() {
for(End_Of_Month_Report__c r : Report)
{
r.OT_Actual_Station_1__c = dummyReport.OT_Actual_Station_1__c;
r.Hours_Planned_Station_1__c = dummyReport.Hours_Planned_Station_1__c;
r.Hours_Worked_Station_1__c = dummyReport.Hours_Worked_Station_1__c;
r.OPs_Taken_Station_1__c = dummyReport.OPs_Taken_Station_1__c;
r.OP_04_Delays_Station_1__c = dummyReport.OP_04_Delays_Station_1__c;
r.Sales_Call_Customer_Comments_1__c = dummyReport.Sales_Call_Customer_Comments_1__c;
r.Customer_Issue_1__c = dummyReport.Customer_Issue_1__c;
}

system.debug('xxxxxxxxxxxxxxxxx'+ Report);
insert Report;
PageReference gorecord = new PageReference('/a1N/o');
gorecord.setRedirect(true);
return gorecord; }}

 The basic idea is to create a "dummy" sObject, bind the fields in the table to it and then copy it's values to the Reports before saving.

This was selected as the best answer
Matt_Matt_
I am sure there are mistakes, but thanks for taking a swing at it! I will test this very shortly and let you know how it worked. Afterwords I will close.

Matt_
Matt_Matt_
Your solution works! Thank you DZ.

Regards,

Matt_