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
Frank CarterFrank Carter 

wrapper class: method to process selected

Hello,
 I need help with a method, processSelected. This method have to change the data in a list of records selected changing only the mont with the current month.
I follow this: https://developer.salesforce.com/page/Wrapper_Class
Controller:
public class SearchWithWrapperC {
    
    public  Date StartDate {get;set;}
    public  Date EndDate {get;set;}
    private Boolean changed {get;set;}
    
    public List<WrapperClass> listBD {get;set;}
    public String SelectedBdId {get;set;}
    
    public void loadData() {
        listBD = new List<WrapperClass>();
        for(Billing_Detail__c  cr : [Select Id,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate  Order by Monthly_Forecast__c ]){
            listBD.add(new WrapperClass (cr, false));
        }
    }
    
    	public List<WrapperClass> getBilling() {
		listBD = new List<WrapperClass>(); 
        for(Billing_Detail__c  cr : [Select Id,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate  Order by Monthly_Forecast__c ]){
            listBD.add(new WrapperClass (cr, false));
        }
				
   		 return listBD;
		}
		    
   public PageReference processSelected() {
       Integer m = Date.Today().Month();
       List<Billing_Detail__c> selectedBD = new List<Billing_Detail__c>();
       for(WrapperClass bd: getBilling()){
           if(bd.check_box== true){
               selectedBD.add(bd.cs);
           } 
       }
        for(Billing_Detail__c cs: selectedBD) {
         cs.Monthly_Forecast__c = Date.newinstance(  cs.Monthly_Forecast__c.year() , m ,  cs.Monthly_Forecast__c.day() );
          update selectedBD;
            System.debug('The value is: ' + cs.Monthly_Forecast__c );   
       }
       
     
       return null;
       
   }
        
    public class WrapperClass {
        public Billing_Detail__c  cs {get; set;}
        public Boolean check_box {get; set;}
        
        public WrapperClass(Billing_Detail__c  c){
            this.cs = c;
            this.check_box = false;
        }
    }
}
vf:
<apex:page controller="SearchWithWrapperC" docType="html-5.0" id="pg">
    
    <apex:form >
        <apex:pageBlock title="Billing Details Search Page" >
            <br/>
            <br/>
            <apex:actionRegion >
                <center>
                    <apex:outputLabel value="Start Date"/>
                    <apex:input value="{!StartDate}" type="date" /><br/>
                    <apex:outputLabel value="End Date "/>
                    <apex:input value="{!EndDate}" type="date" /> 
                </center>
            </apex:actionRegion>  
            <br/>
            
            <div align="center" draggable="false" >            
                <apex:commandButton value="Search" action="{!loadData}" style="text-align:left;" />               
                <apex:commandButton value="Moves to next month" style="text-align:left;" onclick="if(!confirm('If you click ok all the selected billing details will be paid for the current month. Are you sure? ')) return false;" action="{!processSelected}" />  
            </div>        
        </apex:pageBlock>
        
        <apex:pageBlock id="pgblk">
            <apex:pageBlockTable value="{!listBD}" var="b">
                <apex:column >
                    <apex:inputCheckbox value="{!b.check_box}" />
                </apex:column>
                <apex:column value="{!b.cs.Name}"/>
                <apex:column value="{!b.cs.SF_Opportunity_Id__c}"/>
                <apex:column value="{!b.cs.Billing_Type__c}"/>
                <apex:column value="{!b.cs.Billing_Period__c}"/>    
                <apex:column value="{!b.cs.Monthly_Forecast__c}"/>
                <apex:column value="{!b.cs.End_of_Billing__c}"/>
                <apex:column value="{!b.cs.Amount__c}"/>
                <apex:column value="{!b.cs.Billing_Status__c}"/>   
                <apex:column >                   
                    <apex:outputLink title="" value="/{!b.cs.Id}/e?retURL=/apex/{!$CurrentPage.Name}" target="_blank" style="font-weight:bold">EDIT</apex:outputLink>
                </apex:column>    
            </apex:pageBlockTable>   
            
        </apex:pageBlock>        
    </apex:form>
</apex:page>
The method doesn't work. Can someone help me?


Thanks.

 
Best Answer chosen by Frank Carter
Frank CarterFrank Carter
Solved By my self:
public List<WrapperClass> getBilling() {
            if(listBD == null) {

		listBD = new List<WrapperClass>(); 
        for(Billing_Detail__c  cr : [Select Id,SF_Opportunity_Id__c, Name,Billing_Type__c, Billing_Period__c , Monthly_Forecast__c,End_of_Billing__c, Amount__c, Billing_Status__c   from Billing_Detail__c Where Billing_Status__c='Authorized for Billing'AND Monthly_Forecast__c>=:StartDate AND Monthly_Forecast__c <= :EndDate  Order by Monthly_Forecast__c ]){
            listBD.add(new WrapperClass (cr, false));
        }
        }		
   		 return listBD;
		}