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
JBabuJBabu 

Test class for wrapper class

Hi,

 

I need to write test class for wrapper class coverage.

 

CLASS
----------
public without sharing class OppController {
    
    public OppController() {

    }
private class wrapOpp {
        public Integer index { get; set; }
        public Opportunity opp {get; set;}
        public String error {get; set; } 
        public List<SelectOption> allEquipments {
            get {
                List<SelectOption> Equipments = new List<SelectOption>();
                Equipments = OppUtil.allEquipmentOptions;
                return Equipments;
            }
        }
        
        public List<SelectOption> allNotifyDates {
            get {
                List<SelectOption> NotifyDates = new List<SelectOption>();
                if(opp.Property__c != null) {
                    NotifyDates = OppUtil.allNotifyDateOptions.get(opp.Equipment__c);
                }
                return NotifyDates;
            }
        }

    private wrapOpp(Integer ndx, Opportunity o, String err) {
            index = ndx;
            opp = o;
            error = err;           
        }
    }
  }
 

 

  TEST CLASS (wrapper line)
  -------------------------------------
 
 public class testOppclass{

 

 public static testmethod void TestOppMethod(){


  OppController.wrapperOpp Wrapvar = new OppController.wrapperOpp();

}

}

 

 

When I declare a variable I am getting error message as

" Type not visible ; OppController.wrapperOpp" on the line "OppController.wrapperOpp Wrapvar = new OppController.wrapperOpp();"

 

Please help me in identifying the issue.

 

Thanks,

JBabu.

Best Answer chosen by Admin (Salesforce Developers) 
Rajesh SriramuluRajesh Sriramulu

Hi

 

use this

Integer nd;

Opputunity o1 = new Opputunity();

String str;

 

 try to make public in private wrapOpp(Integer ndx, Opportunity o, String err) { here

OppController.wrapOpp Wrapvar = new OppController.wrapOpp (nd,o1,str);

 

Regards,

Rajesh.

All Answers

Rajesh SriramuluRajesh Sriramulu

Hi

 

use this

Integer nd;

Opputunity o1 = new Opputunity();

String str;

 

 try to make public in private wrapOpp(Integer ndx, Opportunity o, String err) { here

OppController.wrapOpp Wrapvar = new OppController.wrapOpp (nd,o1,str);

 

Regards,

Rajesh.

This was selected as the best answer
JBabuJBabu

Thank you Rajesh...

NehaKSNehaKS

I used the same approach but getting error as

Invalid type: ctrl.wrpsch 

 

Here goes my code:--

public class lisch
      { 

 lisch(ApexPages.StandardController stdControlle){  }
        

public class wrpsch
      { 
        public OpportunityLineItemSchedule c {get; set;}
        public wrpsch(OpportunityLineItemSchedule sc) 
        {
            c = sc;    
        }
     
      }

 

Apex Test Class:--

 

ApexPages.StandardController stdController= new ApexPages.StandardController(o);
        lisch ctrl=new lisch(stdController);

     OpportunityLineItemSchedule olistest1=new OpportunityLineItemSchedule();
        ctrl.wrpsch = new ctrl.wrpsch(olistest1);

 

 

apex class "lisch" is an extension class.

Rajesh SriramuluRajesh Sriramulu

Hi

 

lisch.wrpsch lw = new lisch.wrpsch(olistest1);

 

Try this it will helps u.

 

Regards,

Rajesh.

NehaKSNehaKS

It worked .. :) thank you

Anu Raj.ax1269Anu Raj.ax1269
thanks that was great.