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
Carter85Carter85 

Need help updating variables in a wrapper class list onchange

I don't know why I'm spacing on the right way to do this at the moment, but I could use some help.
I have a list contained in a wrapperclass that I want to be able to update the associated values for when they change based on user interaction and then pull the new values in to update records when the user chooses to update their modifications.
 This is my class:
public with sharing class CM_BatchEditClass{

	private ID  id	{get;set;}
    
    public ID conID	{get;set;}
    
    public List<MG_Contract_Holder__c> editList	{get;set;}
    
    public List<ContractWrapper> contractList    {get;set;}
    
    public decimal fillAmt	{get;set;}
    public decimal remitUpd	{get;set;}
    	
    public CM_BatchEditClass(ApexPages.StandardController controller){
        editList = new list<MG_Contract_Holder__c>();
        contractList = new list<ContractWrapper>();
        }
	
	public class contractWrapper{
        //the contract records
        public MG_Contract_Holder__c rContract  {get;set;}
                
       	public ID conID {get;set;}
        public decimal remitUpd	{get;set;}
        /*
        *   Constructor initializes the contract reference
        */
    public contractWrapper(MG_Contract_Holder__c c){
        rContract = c;
        conID = c.ID;
        remitUpd = 0.00;
        }
        }
	
	public void initList(){
       	id = ApexPages.currentPage().getParameters().get('id');
       	
       	editList = [SELECT Full_Name__c,
       					   Contract_Number__c,
       					   Received_Date__c,
       					   Policy_Type__c,
       					   Class__c,
       					   Term__c,
       					   Benefits_Options__c,
       					   Remit_Amount__c
       					   FROM MG_Contract_Holder__c
       					   WHERE Batch__c =: id];
    					   
    	for(MG_Contract_Holder__c c : editList){
    		contractList.add(new contractWrapper(c));
    						}			
    					   	}
    
    public pageReference saveChanges(){
    	conID = Apexpages.currentPage().getParameters().get('conID');
    	remitUpd = decimal.valueof(Apexpages.currentPage().getParameters().get('newRemit'));
    	
    	system.debug('remitUpd: ' + remitUpd);
    	//MG_Contract_Holder__c toUpdate = [SELECT ID FROM MG_Contract_Holder__c WHERE ID =: conID];
    	//toUpdate.Remit_Amount__c = remitUpd;
    	
    	//update toUpdate;
    	
    	ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Contract updated.'));
    	return null;
    	}	
    
    public pageReference fillDown(){
    	for(MG_Contract_Holder__c c : editList){
    		c.Remit_Amount__c = fillAmt;
    		}
    		ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'Contract(s) updated.'));
    		update editList;
    		
    		return null;
    		}

	
}
And here is the form it's interacting with:
<apex:form >   
       <apex:sectionHeader title="Contract Remittance" subtitle="Payment Application"/>              
       		<apex:pageblock >
       <apex:messages style="color:red;text-align:left;"/>              
       			<apex:outputLabel >Fill Down Amont:</apex:outputLabel>
       			<apex:inputText value="{!fillAmt}" />
       			<apex:commandButton value="Apply" action="{!fillDown}" />
       			
            		<apex:pageBlockTable value="{!contractList}" var="c">
						<apex:column headervalue="Customer Name:">
							<apex:outputField value="{!c.rContract.Full_Name__c}"/>
						</apex:column>
						<apex:column headervalue="Contract Number:" style="text-align:center">
							<apex:outputField value="{!c.rContract.Contract_Number__c}"/>
						</apex:column>
						<apex:column headervalue="Policy:" style="text-align:center">
							<apex:outputField value="{!c.rContract.Policy_Type__c}"/>
						</apex:column>
						<apex:column headervalue="Term:" style="text-align:center">
							<apex:outputField value="{!c.rContract.Term__c}"/>
						</apex:column>
						<apex:column headervalue="Class:" style="text-align:center">
							<apex:outputField value="{!c.rContract.Class__c}"/>
						</apex:column>
						<apex:column headervalue="Option:" style="text-align:center">
							<apex:outputField value="{!c.rContract.Benefits_Options__c}"/>
						</apex:column>
						<apex:column headervalue="Remit:" style="text-align:center">
							<apex:inputField value="{!c.rContract.Remit_Amount__c}"/>
						</apex:column>
						<apex:column>
						<apex:commandButton value="Save" action="{!saveChanges}" rerender="hiddenBlock">
            				<apex:param name="conID" value="{!c.rContract.ID}" assignTo="{!conID}"/>
                			<apex:param name="newRemit" value="{!c.remitUpd}" assignTo="{!remitUpd}"/>	
                		</apex:commandButton>
						</apex:column>
					</apex:pageBlockTable>
					<apex:pageBlock id="hiddenBlock" rendered="false"></apex:pageBlock>
       		</apex:pageblock>
       		 
  </apex:form>
The variable in question, at the moment, which I would like to update on the fly and have ready for when the user clicks the save button is the
{!c.remitUpd} parameter, which would contain any updated value the user has entered in the {!c.rContract.Remit_Amount__c} field and I've never done it before with a dynamic list like this so I haven't been able to work out the right means of passing the new value to the parameter so that it updates beyond the inital set value of 0.00 and therefore any help would be appreciated.
 
Best Answer chosen by Carter85
Shashikant SharmaShashikant Sharma
Do this in your saveChanges method
List<MG_Contract_Holder__c< listMGContractToEdit = new List<MG_Contract_Holder__c>();
// You need to loop over contractList 
for( contractWrapper cw : contractList ) {
listMGContractToEdit.add( cw.rContract  );
}

update listMGContractToEdit;

 

All Answers

Shashikant SharmaShashikant Sharma
Do this in your saveChanges method
List<MG_Contract_Holder__c< listMGContractToEdit = new List<MG_Contract_Holder__c>();
// You need to loop over contractList 
for( contractWrapper cw : contractList ) {
listMGContractToEdit.add( cw.rContract  );
}

update listMGContractToEdit;

 
This was selected as the best answer
Carter85Carter85
That was exactly it.  Much appreciated.