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

Test class Error

Hello Friends i have wriiten a wrapper class.It is working correctly but when i am writting the test class for it i am getting error 

Error: Compile Error: Invalid type: CategoryWrapper at line 15 column 36


public class Cls_OppRelatedList {
List<categoryWrapper> categories {get;set;}
public id  aid{get;set;}
public string surl = '';
public list<opportunity> opportunityList{get;set;}

 public Cls_OppRelatedList(ApexPages.StandardController controller) {
opportunityList=new list<opportunity>();
categories=new List<categoryWrapper>();
if(ApexPages.currentPage().getUrl() != null)
     aid= ApexPages.currentPage().getParameters().get('id');
    opportunityList=[select name,accountid,stagename,closedate,Amount from opportunity where Accountid=:aid ] ;
public List<categoryWrapper> getCategories() {
     integer i = 0;
     for(opportunity a: opportunityList)
           CategoryWrapper lw = new CategoryWrapper(a);
             return categories;  

public class CategoryWrapper {
   public string oppname { get; set;}
   public date closedate { get; set;}
   public string stagename { get; set;}
   public id opportunityid{get;set;}
   public CategoryWrapper(opportunity c){;



Test Class :

Public class Test_Cls_OppRelatedList
   Public static testMethod void OppRelatedList()
       List<Opportunity> Opp = New List<opportunity>();
       Account a=new Account();
       insert a;
       Opp = [select name,accountid,stagename,closedate,Amount from opportunity limit 2];
       ApexPages.StandardController controller=new ApexPages.StandardController(a);  
       Cls_OppRelatedList obj = new Cls_OppRelatedList(controller);
       CategoryWrapper obj1 = New CategoryWrapper(new Opportunity(Name ='Test Oppty', CloseDate =, StageName = 'Closed Lost', AccountId = a.Id));


 Pls let me know where i am wrong and how can we correct this?



When referencing an inner class from another file, you need to use the top level class like this: 




So your test class uses this syntax:


Cls_OppRelatedList.CategoryWrapper obj1 = New Cls_OppRelatedList.CategoryWrapper(new Opportunity(Name ='Test Oppty', CloseDate =, StageName = 'Closed Lost', AccountId = a.Id));