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
Neha KakrooNeha Kakroo 

line 9, column 54: Type is not visible: customObjectController.CustomObjectWrapper

Hi I am trying to write the test class for the below code but getting the above mentioned error. I guess this is due to the wrapper class being private. Can anybody pls help me with the test class.

 

The class is:

public class customObjectController{


    public static Integer indexGen {get; set;} //index generator
    public List<CustomObjectWrapper> coList;
    public Integer numRows {get; set;}

    
    /*
     * Wrapper class for holding a 'CustomObjects__c' record and its row index together.
     * The row index is used to delete the row using commandLink
     */
    private class CustomObjectWrapper {
        private CustomObjects__c customObject;
        private Integer index;
     
     
     public CustomObjectWrapper() {
            this.customObject = new CustomObjects__c();
            this.index = indexGen++;
        }
        
        public CustomObjects__c getCustomObject() {
            return customObject;
        }
        
        public Integer getIndex() {
            return index;
        }
    }
        
    /*
     * Constructor
     * -----------
     * Initializes 'coList' and 'numRows'
     */
    public customObjectController(ApexPages.StandardController controller) {
        if(indexGen == null) indexGen = 1;
        coList = new List<CustomObjectWrapper>();
        numRows = 1;
    }
    public List<CustomObjectWrapper> getCoList() {
        return coList;
    }


     
    /*
     * upserts all records currently in the 'coList'
     */
    public PageReference save() {
        if(coList.size()==0)
            return new PageReference('/' + ApexPages.currentPage().getParameters().get('retURL'));
        try {
            List<CustomObjects__c> tempList = new List<CustomObjects__c>();
            for(Integer i=0; i<coList.size(); ++i)
                tempList.add(coList[i].getCustomObject());
            upsert(tempList);
            return new PageReference('/' + ApexPages.currentPage().getParameters().get('retURL'));
        } catch (System.DMLException ex) {
            ApexPages.addMessages(ex);
            return null;
        }
    }
    
    
    
     /*
     * appends new records to the 'coList'.
     * The number of records added is determined by the value of 'numRows'
     * Issues with the method: Not working if mandatory fields are left empty
     */
    public void add() {
          try {
            if(numRows > 0)
                for(Integer i=0; i<numRows; ++i)
                    coList.add(new CustomObjectWrapper());
        } catch (Exception ex) {
             ApexPages.addMessages(ex);
        }
   }
    
    
    /*
     * Clears all records from the 'coList'
     * Issues with the method: Not working if mandatory fields are left empty
     */        
    public void clear(){
        coList.clear();
        numRows = 1;
         }
     

    /*
     * deletes a record from 'coList' depending on the 'index' of 'CustomObjects__c' within the 'CustomObjectWrapper' class
     */
     public void delRecords(){
        try {
            Integer delIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('delRow'));
            
            for(Integer i=0; i<coList.size(); ++i)
                if(coList[i].index == delIndex) {
                    coList.remove(i);
                    break;
                }
        } catch (Exception ex) {
            ApexPages.addMessages(ex);
        }
    }
    
       
             
   }

the test class that I have written is:

@isTest

public class customObjectController_Test{

public static testMethod void testcls(){
CustomObjects__c cust = new CustomObjects__c();
ApexPages.StandardController sc = new ApexPages.StandardController(cust);
customObjectController obj = new customObjectController(sc);
customObjectController.CustomObjectWrapper wra = new customObjectController.CustomObjectWrapper();
obj.save();
obj.add();
obj.clear();
obj.delRecords();
wra.getIndex();
wra.getcustomObject();
}
}



Rahul SharmaRahul Sharma

try this

@isTest

public class customObjectController_Test{

public static testMethod void testcls(){
CustomObjects__c cust = new CustomObjects__c();
ApexPages.StandardController sc = new ApexPages.StandardController(cust);
customObjectController obj = new customObjectController(sc);
customObjectController.coList.add(cust);// Add records to wrapper class list
obj.save();
obj.add();
obj.clear();
obj.delRecords();
wra.getIndex();
wra.getcustomObject();
}
}

 

Neha KakrooNeha Kakroo

I am not able to compile the class.I am getting the below error:

"Method does not exist or incorrect signature: customObjectController.coList.add(SOBJECT:CustomObjects__c) "

Rahul SharmaRahul Sharma

oops, its should be

object.list.add(record);

 

customObjectController obj = new customObjectController(sc);
obj.coList.add(cust);// Add records to wrapper class list

 

Neha KakrooNeha Kakroo

No Luck...

 

Compile Error: Incompatible element type SOBJECT:CustomObjects__c for collection of customObjectController.CustomObjectWrapper at line 7 column 1

 

Also how can we define the obj of wrapper class? the class is private so it throws an error type is invisible...