You need to sign in to do that
Don't have an account?
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" /> | <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!
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.
Controller.
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
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.
Controller.
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.
Matt_
Regards,
Matt_