+ Start a Discussion
vishwa attikerivishwa attikeri 

how to Wrapper class method in main class

Hi 

 

Please can anybody  tell, is it possible to take wrapper class method in main class, if yes please tel how it will do

 

and please see this code it is used to display the total for perticular date, 

how can i calculate total of toal for a month

public with sharing class Finalpaymonth {

Public  String amount{get;set;}
public PageReference searchAction(){
            prepareMap();   
        return null;
    }
 List<Wrappertimecard> wraptimelist = new List<Wrappertimecard>();
 public void prepareMap(){
 Integer t1=0;Integer t2=0;Integer t3=0    
 Integer total=0;
 
 wraptimelist = new List<Wrappertimecard>();

 List<Time_Card__c> empList = [select 
Ambulation_walk_room_to_room__c,Assist_getting_returning_equipment__c,Assist_with_binders__c 
from Time_Card__c where Month__c=:month order by date__c ASC];
        
        for(Time_Card__c emp: empList){
                   
if(emp.Ambulation_walk_room_to_room__c!=null && emp.Ambulation_walk_room_to_room__c!='XX' && emp.Ambulation_walk_room_to_room__c!='X')
{t1=Integer.valueof(emp.Ambulation_walk_room_to_room__c);}  else{t1=0;}
        
if(emp.Assist_getting_returning_equipment__c!=null && emp.Assist_getting_returning_equipment__c!='XX' &&  emp.Assist_getting_returning_equipment__c!='X')
{t2=Integer.valueof(emp.Assist_getting_returning_equipment__c);} else{t2=0;}
        
if(emp.Assist_with_binders__c!=null && emp.Assist_with_binders__c!='XX' && emp.Assist_with_binders__c!='X')
{t3=Integer.valueof(emp.Assist_with_binders__c);}   else{t3=0;}
        
        total=t1+t2+t3;
     
 wraptimelist.add(new Wrappertimecard(emp.Days__c,emp.day__c,amount,total));
          
		 
        }
              
    } 
 
    public List<Wrappertimecard> getWrapSummaryList(){
        return wraptimelist;
    }
  
//wrapper class    
    public class Wrappertimecard{
    public String perunitamount{get;set;}   
    public String tdate{get;set;}
    Public String days{get;set;}
    public Integer total1 {get;set;}
              
     public Integer getTotal(){
      return total1;
     }     
     public Wrappertimecard(String dat,String day,String prunitamt,Integer t1){
     tdate = dat;
     Days=day;
     perunitamount=prunitamt;
     total1 = t1;
     }
  }
}

 

 

Thanks

 

bob_buzzardbob_buzzard

Can you clarify what you mean by "take wrapper class method in main class"?  E.g. are you wanting to call a method on a wrapper class instance from the main class, or something else?

vishwa attikerivishwa attikeri

Hi,

 

i want to call this gettotal() wrapper class method in finaypaymonth class

bob_buzzardbob_buzzard

You can iterate your list of wrapper classes and call getTotal on each of those as follows:

 

for (Wrappertimecard wrap : wraptimelist)
{
   System.debug('Total = ' + wrap.getTotal());
}