You need to sign in to do that
Don't have an account?

2 wrapper class in single class not working
Hi all,
This one is driving me crazy, as I cannot see what wrong I am doing. I have 2 wrapper class within single controller class.
One for Estimate_Step__c object and other for Misc_Cost__c object, both are child object to Estimate__c object.
I have a detail page button on Estimate__c object, that takes user to a VF page, that displays Master record and all related records for both these objects. Also on VF page, I have "Add New" button for both these objects/datatables. "Add New" adds a record with default values to respective list, so users can udpate it VF page.
While it works great for Estimate_Steps__c object, it does not work for Misc_Cost__c object, in reality they are ditto copy, just change in variable names. When user changes values for Misc_Cost__c records in VF, it is not passed to the controller.
Please find the code below. Thanks in advance..
VF page
<apex:outputPanel id="pnlEstimateSteps"> <apex:outputLabel value="Step II: Choose Estimate Steps" styleClass="bold" /><br/> <apex:pageBlock > <apex:pageBlockButtons location="bottom"> <apex:commandButton action="{!addStep}" value="New (RL) Estimate Step" rerender="pnlEstimateSteps" status="addStepStatus" immediate="true"/> <apex:actionStatus startText="loading..." id="addStepStatus"/> </apex:pageBlockButtons> <apex:pageBlockTable id="tblEstimateSteps" value="{!estimateWrapperList}" rendered="{!estimateWrapperList.size!=0 && NOT(ISNULL(estimateWrapperList))}" style="width:800px" var="e"> <apex:column headerValue="Select" > <apex:inputCheckbox value="{!e.selected}" style="width:20px"/> </apex:column> <apex:column headerValue="Step Order" rendered="true"> <apex:inputText id="stepOrder" value="{!e.stepOrder}" style="width:20px" required="true" /> </apex:column> <apex:column > <apex:facet name="header"> {!$ObjectType.Name.Label} </apex:facet> <apex:inputField id="stepName" value="{!e.estimateStep.Name}" style="width:150px" required="true"/> </apex:column> <apex:column > <apex:facet name="header"> {!$ObjectType.Estimate_Step__c.Fields.Hours_Required__c.Label} </apex:facet> <apex:inputField id="stepHrs" value="{!e.estimateStep.Hours_Required__c}" style="width:50px" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> <br/> <apex:outputPanel id="pnlEstimateMisc"> <apex:outputLabel value="Step III: Choose Miscellaneous Costs" styleClass="bold" /><br/> <apex:pageBlock > <apex:pageBlockButtons location="bottom"> <apex:commandButton action="{!addMiscCost}" value="New (RL) Misc. Costs" rerender="pnlEstimateMisc" status="addMiscStatus" immediate="true"/> <apex:actionStatus startText="loading..." id="addMiscStatus"/> <br/><br/><br/> <apex:commandButton action="{!Save}" value="Save" /> <apex:commandButton action="{!Cancel}" value="Cancel" /> </apex:pageBlockButtons> <apex:pageBlockTable id="tblEstimateMisc" value="{!estimateMiscWrapperList}" rendered="{!estimateMiscWrapperList.size!=0 && NOT(ISNULL(estimateMiscWrapperList))}" style="width:800px" var="m"> <apex:column headerValue="Select"> <apex:inputCheckbox value="{!m.selected}" style="width:20px"/> </apex:column> <apex:column > <apex:facet name="header"> {!$ObjectType.RL_Misc_Cost__c.Fields.Misc_picklist__c.Label} </apex:facet> <apex:inputField id="miscName" value="{!m.estimateMisc.Misc_picklist__c}" style="width:200px" required="true" /> </apex:column> <apex:column > <apex:facet name="header"> {!$ObjectType.RL_Misc_Cost__c.Fields.Cost__c.Label} </apex:facet> <apex:inputField id="miscCost" value=" {!m.estimateMisc.Cost__c}" style="width:50px" required="true" /> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel>
Apex class
//Class variables private final Estimate__c estimateRecord; public List<Estimate_Step__c> estimateStepsList {get; set;} public List<RL_Misc_Cost__c> estimateMiscList {get; set;} public list<clsEstimateWrapper> estimateWrapperList {get; set;} public list<clsEstimateMiscWrapper> estimateMiscWrapperList {get; set;} public String qryString; public String prodDescription {get; set;} public Integer stepOrder; public String action {get; set;}. . . . //Wrapper class for Estimate_Step__c public class clsEstimateWrapper{ public Estimate_Step__c estimateStep{get; set;} public Boolean selected {get; set;} public Integer stepOrder {get; set;} /*This is the contructor method. for each new instance set Estimate_Step__c and stepOrder. Selected is true by default */ public clsEstimateWrapper(Estimate_Step__c estStep, Integer stepOrder){ estimateStep = estStep; selected = true; this.stepOrder = stepOrder; } } //Wrapper class for RL_Misc_Cost__c public class clsEstimateMiscWrapper{ public RL_Misc_Cost__c estimateMisc{get; set;} public Boolean selected {get; set;} /*This is the contructor method. for each new instance set RL_Misc_Cost__c. Selected is true by default */ public clsEstimateMiscWrapper(RL_Misc_Cost__c estMisc){ this.estimateMisc = estMisc; selected = true; } } //Save Estimate along with selected Steps public PageReference Save(){ //Estimate header system.Debug('estimateRecord.Name: ' + estimateRecord.Name); system.Debug('estimateRecord.Drawing_No__c: ' + estimateRecord.Drawing_No__c); system.Debug('estimateRecord.Quantity__c: ' + estimateRecord.Quantity__c); Estimate__c clonedEstimate= new Estimate__c(Name=estimateRecord.Name, Drawing_No__c=estimateRecord.Drawing_No__c, Quantity__c=estimateRecord.Quantity__c, Opportunity__c=estimateRecord.Opportunity2__c, Product__c=estimateRecord.Product__c, Estimate_Notes__c=estimateRecord.Estimate_Notes__c, Estimate_UOM__c=estimateRecord.Estimate_UOM__c, Metal_Type__c=estimateRecord.Metal_Type__c, Metal_Cost__c=estimateRecord.Metal_Cost__c, Lbs_babbitt__c=estimateRecord.Lbs_babbitt__c, Shop_Rate__c=estimateRecord.Shop_Rate__c, Est_Standard_Delivery__c=estimateRecord.Est_Standard_Delivery__c, Est_Std_Delivery_Units__c=estimateRecord.Est_Std_Delivery_Units__c, Est_Expedited_Delivery__c=estimateRecord.Est_Expedited_Delivery__c, Est_Exp_Delivery_Units__c=estimateRecord.Est_Exp_Delivery_Units__c, Base_Price_Multiplier__c=estimateRecord.Base_Price_Multiplier__c, Expedited_Multiplier__c=estimateRecord.Expedited_Multiplier__c); try{ //1. Insert Estimate insert clonedEstimate; system.Debug('estimateWrapperList in Save(): ' + estimateWrapperList); //2. Estimate Steps logic //Empty existing estimateSteps List estimateStepsList = new List<Estimate_Step__c>{}; for(clsEstimateWrapper EstimateWrapper : estimateWrapperList){ //Check if Estimate Step is checked if(EstimateWrapper.selected){ system.debug('EstimateWrapper: ' + EstimateWrapper); Estimate_Step__c estimateStep = new Estimate_Step__c(Name=EstimateWrapper.estimateStep.Name, Hours_Required__c=EstimateWrapper.estimateStep.Hours_Required__c, Estimate__c=clonedEstimate.Id, Comments__c= EstimateWrapper.estimateStep.Comments__c); estimateStepsList.add(estimateStep); system.debug('estimateStep: ' + estimateStep); } } //insert Estimate Steps insert estimateStepsList; //3. Estimate Misc Cost logic system.Debug('estimateMiscList in Save(): ' + estimateMiscList); //Empty existing estimateMisc List estimateMiscList = new List<RL_Misc_Cost__c>{}; for(clsEstimateMiscWrapper EstimateMiscWrapper : estimateMiscWrapperList){ //Check if Estimate Misc Cost is checked if(EstimateMiscWrapper.selected){ system.debug('EstimateMiscWrapper: ' + EstimateMiscWrapper); RL_Misc_Cost__c estimateMisc = new RL_Misc_Cost__c(Misc_picklist__c=EstimateMiscWrapper.estimateMisc.Misc_picklist__c, Cost__c=EstimateMiscWrapper.estimateMisc.Cost__c, Comments__c=EstimateMiscWrapper.estimateMisc.Comments__c, RL_Estimate__c=clonedEstimate.Id); estimateMiscList.add(estimateMisc); system.debug('estimateMisc: ' + estimateMisc); } } //insert Estimate Steps insert estimateMiscList; //4. Redirect user to Estimate PageReference pageRef = new PageReference('https://cs9.salesforce.com/'+clonedEstimate.Id); pageRef.setRedirect(false); return pageRef; } catch(DmlException ex){ ApexPages.addMessages(ex); return null; } catch(Exception e){ ApexPages.addMessages(e); return null; } } //Add Dynamic Estimate Step public PageReference addStep(){ estimateWrapperList.add(new clsEstimateWrapper(new Estimate_Step__c(Hours_Required__c=0.0, Comments__c='test', Estimate__c=estimateRecord.Id), stepOrder++)); return null; } //Add Dynamic Misc Cost public PageReference addMiscCost(){ estimateMiscWrapperList.add(new clsEstimateMiscWrapper(new RL_Misc_Cost__c(Cost__c=0.0, Comments__c='test', RL_Estimate__c=estimateRecord.Id))); return null; }
Can you post some of the debug output? I can't see anything obviously wrong.
Bob,
thanks for the reply, but I fig'd it out. There was one little white space in VF page casing this issue.
Now I can sleep like a baby ..