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
vishwa attikerivishwa attikeri 

how to Wrapper class method in main class



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(){
        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 
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;}
 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;
     total1 = t1;






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



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


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());