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
suji srinivasansuji srinivasan 

How to provide constructor value for this apex class?

public class SalaryRewards {

 public List <salaryInfo> lsalaryInfo{get;set;}
        public List <Salary_Detail__c> salarydetail{get;set;}
          
 public SalaryRewards(ApexPages.StandardController controller) 
    {
        lsalaryInfo = new list <salaryInfo>();
        salarydetail = new list<Salary_Detail__c>();
        salarydetail =[SELECT Id, Professional_Tax__c,BasicAllowance__c,HouseRentAllowance__c,Skill_up_Allowance__c,PF__c,SpecialAllowance__c,TotalEarnings__c,TotalDeductions__c, NetPay__c,createdDate FROM Salary_Detail__c WHERE createdDate = THIS_YEAR ];
  
        for(integer i=0;i<System.now().month();i++)
        {
            salaryInfo  sinfo = new salaryInfo ();
            sinfo.month = datetime.newinstance(2013,1,1).addmonths(i).format('MMM');
            sinfo.count = 0;
           lsalaryInfo.add(sinfo);
             system.debug('salary-month===>'+lsalaryInfo);
        }
      
            // lsalaryInfo = new List <salaryInfo>();
     list<Salary_Detail__c> sallist =new list<Salary_Detail__c>();
                  list<Salary_Detail__c> salmainlist =new list<Salary_Detail__c>([SELECT Id, Professional_Tax__c,BasicAllowance__c,HouseRentAllowance__c,Skill_up_Allowance__c,PF__c,SpecialAllowance__c,TotalEarnings__c,TotalDeductions__c, NetPay__c,createdDate FROM Salary_Detail__c WHERE createdDate = THIS_YEAR ]);
            for(Salary_Detail__c sal :salmainlist){
                                     lsalaryInfo.add(new Salary_Detail__c(sal,BasicAllowance__c));
// how to mention value here
//error:Type requires name=value pair construction: Salary_Detail__c

                      system.debug('salary-month===>'+ lsalaryInfo);}
    }}

      
    
            
      
     

        
 

       
        
    
  
Virendra ChouhanVirendra Chouhan

Sorry but i dont know what you are trying to do.
IF you want to add some values on the IsalaryInfo list then there are couple of ways you can add values on a list.
 

List<account> accList = new list<Account>();

1.) When we have object with same data type.
accList.add(accountObj); Here accountObj is the instance of Account object.

2.) When we don't have object, then we can create new instance and in the constructor add fields with values.
accList.add(new Account(Name = 'Test', Phone='123456'));