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
sesidhar ponnada 8sesidhar ponnada 8 

please give test class for this wrapper class

public with sharing class productsinfo {

    public list<wrapper> wrapperlist{get;set;}
    public Sample_Request__c smp{get;set;}
    Public Id recordID{get;set;}
    public List<SelectOption> selectedlistoptions {set;get;}
    public String rowNumber {set;get;}
    public string BatchId{set;get;}
       
    public productsinfo(ApexPages.StandardController controller) {
   
    selectedlistoptions = new list<SelectOption>();
    recordID = controller.getid();
    smp=[ select Product_1__r.name,Product_2__r.name,Product_3__r.name,Product_4__r.name from Sample_Request__c WHERE id =: recordID];
    wrapperlist = new list<wrapper>();
    for( Batch__c BatchList : [select id, Name,batch__c,Product__c,Batch_Identifier__c from batch__c where Sample_Request__r.id=:recordID ] )
    {
       wrapper wrap = new wrapper();
       wrap.selectedproducts=BatchList.Product__c;
       wrap.indexnumber= String.valueOf(wrapperlist.size());
       wrap.extId = BatchList.Batch_Identifier__c;
       wrap.batchnumber=BatchList.batch__c;
       wrapperlist.add(wrap); 
   
    }
    selectedlistoptions.add(new SelectOption('-None-','-None-'));
    If(smp.Product_1__r.name!=null && !string.isblank(smp.Product_1__r.name))
        selectedlistoptions.add(new SelectOption(smp.Product_1__r.name,smp.Product_1__r.name));
    If(smp.Product_2__r.name!=null && !string.isblank(smp.Product_2__r.name))
    selectedlistoptions.add(new SelectOption(smp.Product_2__r.name,smp.Product_2__r.name));
    If(smp.Product_3__r.name!=null && !string.isblank(smp.Product_3__r.name))
    selectedlistoptions.add(new SelectOption(smp.Product_3__r.name,smp.Product_3__r.name));
    If(smp.Product_4__r.name!=null && !string.isblank(smp.Product_4__r.name))
    selectedlistoptions.add(new SelectOption(smp.Product_4__r.name,smp.Product_4__r.name));
    
    
    }

    public void addBatch(){
              if(wrapperlist == null)
              wrapperlist = new List<wrapper>();
              wrapperlist.add(new wrapper());
    }
    
    public void deleteRow(){
      
              String rowNumber = ApexPages.currentPage().getParameters().get('deleteRowNo');
              if(rowNumber != null && wrapperlist != null && !wrapperlist.isEmpty())
              wrapperlist.remove(Integer.valueOf(rowNumber));
              
              if(!String.isBlank(BatchId)){
      
              Batch__c bat = new Batch__c(id=BatchId);
             {
              delete bat;
             }
          }
    }
       
    public void savebatch(){
    
             list<Batch__c> blist = new list<Batch__c>(); 
             for(wrapper bt: wrapperlist){
             Batch__c   bat= new Batch__c();
             If(!String.isBlank(bt.extId))
             {
              bat.id = bt.extId;
             } 
             bat.batch__c= bt.batchnumber;
             bat.Product__c =bt.selectedproducts;
             bat.Sample_Request__c =recordID ;
    
             blist.add(bat);
         
        }
             insert blist;
    } 
   

   public class wrapper{
   
              Public String selectedproducts{get;set;}
              Public String batchnumber{get;set;}
              Public String indexnumber{set;get;}
              public String extId{set;get;}     
              public Batch__c bat{get;set;}
    }

}
PratikPratik (Salesforce Developers) 
Hi Sesidhar,

You can refer to this:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm

For the code you mentioned above, I can see many conditional statements. To achieve the maximum coverage, try to cover both the parts of conditional statement i.e. If as well as else part by updateing the record that you willl insert in the test class.

Thanks,
Pratik