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
neeedhelpneeedhelp 

Test Code for Covering the Wrapper Class

My Apex Class is

  Public class Myclass{

  public class tempconwrapper{
    public boolean selectedcheck;
    public void setselectedcheck(boolean b){this.selectedcheck = b;}
    public boolean getselectedcheck(){return selectedcheck;}
      public Temporary_Contact__c tempcon{get;set;}
      public tempconwrapper(temporary_contact__c temporary){
         tempcon= temporary;
         selectedcheck=false;     
        }

      }
      public list<tempconwrapper> gettemporarycontactlist(){
      list<tempconwrapper> tempwrapperlist=new list<tempconwrapper>();
      list<Temporary_contact__c> TemporaryList = [select  id,Name,First_Name__c,Last_Name__c,Email__c,contact_list__c,Installment__c,Sno__c,Check_temp__c,Map_Contact__c,OrderNumber__c,Recurring__c,Xmldata__c,Master_Transaction_Number__c from Temporary_contact__c  order by createddate desc  ];
      for(Temporary_Contact__c  tempconlist: TemporaryList ){
        tempwrapperlist.add(new tempconwrapper(tempconlist));
     }
      return wrapperlist;
     }

     public pagereference processtempcon(){
      set<Temporary_contact__c> tempconset = new set<Temporary_contact__c>();
           for(tempconwrapper temp: gettemporarycontactlist()){             
                     if(temp.selectedcheck == true) { //this Value is always false in the     constructor
                        //my code                                       
                      }                   
                  }     
          return null;      
        }
     }

 My Test Class for this is

 myclass temporary = new myclass();
 Temporary_Contact__c tc = new      Temporary_Contact__c(OrderNumber__c='1321161610784412',First_Name__c='First',Last_Name__c='Last',Map_Contact__c=con.id,Installment__c=2,Check_Temp__c=true,Master_Transaction_Number__c='1210111712415518392');
insert tc;                
 batchtemporarycls.tempconwrapper tempclass = new batchtemporarycls.tempconwrapper(tc);  
 boolean b = tempclass.getselectedcheck();
 tempclass.setselectedcheck(b);
 temporary.gettemporarycontactlist();  

 Tried different ways to cover the if(temp.selectedcheck == true) part but nothing helps.Any help would be greatly appreciated

 

Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
hitesh90hitesh90

Hi,

 

I have updated the code. see below

Public class Myclass{
	public class tempconwrapper{
		public boolean selectedcheck;
		public void setselectedcheck(boolean b){this.selectedcheck = b;}
		public boolean getselectedcheck(){return selectedcheck;}
		public Temporary_Contact__c tempcon{get;set;}
		public tempconwrapper(temporary_contact__c temporary){
			tempcon= temporary;
			selectedcheck=false;     
		}

	}
	public list<tempconwrapper> gettemporarycontactlist(){
		list<tempconwrapper> tempwrapperlist=new list<tempconwrapper>();
		list<Temporary_contact__c> TemporaryList = [select  id,Name,First_Name__c,Last_Name__c,Email__c,contact_list__c,Installment__c,Sno__c,Check_temp__c,Map_Contact__c,OrderNumber__c,Recurring__c,Xmldata__c,Master_Transaction_Number__c from Temporary_contact__c  order by createddate desc  ];
		
		tempconwrapper objtempconwrapper;
		for(Temporary_Contact__c  tempconlist: TemporaryList ){
			objtempconwrapper = new tempconwrapper(tempconlist);
			objtempconwrapper.tempcon = tempconlist;
			if(test.isrunningtest() == true){
				objtempconwrapper.selectedcheck = true;
			}
			tempwrapperlist.add(objtempconwrapper);			
		}
		return wrapperlist;
	}

	public pagereference processtempcon(){
		set<Temporary_contact__c> tempconset = new set<Temporary_contact__c>();
		for(tempconwrapper temp: gettemporarycontactlist()){             
			if(temp.selectedcheck == true) { //this Value is always false in the     constructor
				//my code                                       
			}                   
		}     
		return null;      
	}
}

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

All Answers

hitesh90hitesh90

Hi,

 

You have to made some change in your controller. see below updated code. i have changed code in this method : gettemporarycontactlist()

 

Public class Myclass{
	public class tempconwrapper{
		public boolean selectedcheck;
		public void setselectedcheck(boolean b){this.selectedcheck = b;}
		public boolean getselectedcheck(){return selectedcheck;}
		public Temporary_Contact__c tempcon{get;set;}
		public tempconwrapper(temporary_contact__c temporary){
			tempcon= temporary;
			selectedcheck=false;     
		}

	}
	public list<tempconwrapper> gettemporarycontactlist(){
		list<tempconwrapper> tempwrapperlist=new list<tempconwrapper>();
		list<Temporary_contact__c> TemporaryList = [select  id,Name,First_Name__c,Last_Name__c,Email__c,contact_list__c,Installment__c,Sno__c,Check_temp__c,Map_Contact__c,OrderNumber__c,Recurring__c,Xmldata__c,Master_Transaction_Number__c from Temporary_contact__c  order by createddate desc  ];
		
		tempconwrapper objtempconwrapper;
		for(Temporary_Contact__c  tempconlist: TemporaryList ){
			objtempconwrapper = new tempconwrapper();
			objtempconwrapper.tempcon = tempconlist;
			if(test.isrunningtest() == true){
				objtempconwrapper.selectedcheck = true;
			}
			tempwrapperlist.add(objtempconwrapper);			
		}
		return wrapperlist;
	}

	public pagereference processtempcon(){
		set<Temporary_contact__c> tempconset = new set<Temporary_contact__c>();
		for(tempconwrapper temp: gettemporarycontactlist()){             
			if(temp.selectedcheck == true) { //this Value is always false in the     constructor
				//my code                                       
			}                   
		}     
		return null;      
	}
}

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

neeedhelpneeedhelp

Getting error as Constructor not defined: [batchtemporarycls.tempconwrapper].<Constructor>()

 

at

objtempconwrapper = new tempconwrapper();

How Should I Overcome this problem.

hitesh90hitesh90

Hi,

 

I have updated the code. see below

Public class Myclass{
	public class tempconwrapper{
		public boolean selectedcheck;
		public void setselectedcheck(boolean b){this.selectedcheck = b;}
		public boolean getselectedcheck(){return selectedcheck;}
		public Temporary_Contact__c tempcon{get;set;}
		public tempconwrapper(temporary_contact__c temporary){
			tempcon= temporary;
			selectedcheck=false;     
		}

	}
	public list<tempconwrapper> gettemporarycontactlist(){
		list<tempconwrapper> tempwrapperlist=new list<tempconwrapper>();
		list<Temporary_contact__c> TemporaryList = [select  id,Name,First_Name__c,Last_Name__c,Email__c,contact_list__c,Installment__c,Sno__c,Check_temp__c,Map_Contact__c,OrderNumber__c,Recurring__c,Xmldata__c,Master_Transaction_Number__c from Temporary_contact__c  order by createddate desc  ];
		
		tempconwrapper objtempconwrapper;
		for(Temporary_Contact__c  tempconlist: TemporaryList ){
			objtempconwrapper = new tempconwrapper(tempconlist);
			objtempconwrapper.tempcon = tempconlist;
			if(test.isrunningtest() == true){
				objtempconwrapper.selectedcheck = true;
			}
			tempwrapperlist.add(objtempconwrapper);			
		}
		return wrapperlist;
	}

	public pagereference processtempcon(){
		set<Temporary_contact__c> tempconset = new set<Temporary_contact__c>();
		for(tempconwrapper temp: gettemporarycontactlist()){             
			if(temp.selectedcheck == true) { //this Value is always false in the     constructor
				//my code                                       
			}                   
		}     
		return null;      
	}
}

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

This was selected as the best answer