I have a helper class that has a wrapper class in it. I use the wrapper to return two lists in a method.


public static revenueWrapper createRevenue(List<Project_Submission__c> projSubList, Map<String, Period> periodMap)
    revenueWrapper rev = new revenueWrapper();

    for(Project_Submission__c ps : projSubList)
            Revenue_Pipeline__c revPipe = new Revenue_Pipeline__c();
                revPipe.External_Id__c = extCom;
                revPipe.NPD_Forecast_Category__c = 'Commercial Budget';
                revPipe.CurrencyIsoCode = ps.CurrencyIsoCode;
                revPipe.Project_Submission__c = ps.Id;

            rev.revPipeSchedule.addAll(createschedule(ps.Id, launch));

    public class revenueWrapper
    List<Revenue_Pipeline__c> revPipe = new List<Revenue_Pipeline__c>();
    List<Revenue_Pipeline_Schedule__c> revPipeSchedule = new List<Revenue_Pipeline_Schedule__c>();

Now in my test I'm sending info to the method and returning a result:

 @isTest static void testcreateRevenue_B1()
    List<Project_Submission__c> ps = [
        SELECT  Id, 
        FROM Project_Submission__c];
    ps[0].Target_Launch_Date__c = System.Date.today();
    ps[0].Year_1_Commercial_Budget__c = 1000;

    List<Period> periodList = NPD_ProjectSubmissionHelper.getfiscalPeriod();
    Map<String, Period> periodMap = NPD_ProjectSubmissionHelper.makeMap(periodList);

        NPD_ProjectSubmissionHelper.revenueWrapper results = new NPD_ProjectSubmissionHelper.revenueWrapper();
        results = NPD_ProjectSubmissionHelper.createRevenue(ps, periodMap);

        System.debug('results are:: ' + results);

        //System.assertEquals(1, results,
        //'The revenue should have been created');

In the dev console in the debug log I can see that the the revPipe list is populated from the wrapper

|DEBUG|results are:: revenueWrapper:[revPipe=(Revenue_Pipeline__c:{External_Id__c=a0Gm00000037U18EAE-CommercialBudget, NPD_Forecast_Category__c=Commercial Budget, CurrencyIsoCode=USD, Project_Submission__c=a0Gm00000037U18EAE})...

My problem is when I try to reference the list I get the error:

Variable is not visible: NPD_ProjectSubmissionHelper.revenueWrapper.revPipe

How can I get to the wrapper list to assert on? Changing the class to @testVisible does nothing

1 Answer 1


The wrapper class's instance variables have no access specifier, meaning that they get private as the default:

[private] List<Revenue_Pipeline__c> revPipe = ;
[private] List<Revenue_Pipeline_Schedule__c> = ;

It's the instance variables that need the @TestVisible annotation, rather than their enclosing class. That will make them available in test code.

  • Link to doc, in case you want to put that in: developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
    – sfdcfox
    Commented May 31, 2019 at 20:34
  • Thanks, @sfdcfox! Added inline.
    – David Reed
    Commented May 31, 2019 at 20:35
  • I read a few posts where someone wrote making @testVisible is a last resort. In theory I can make it public list<revenue pipeline>.. and get the same results? Commented May 31, 2019 at 20:43
  • 2
    @DanWooding Yeah, that'll work fine. The only reason I am aware of not to use @TestVisible is based on (a) ideological purity about OOP encapsulation or (b) concern about making the tests fragile by inspecting the inner state of your classes that are felt to be implementation details. public of course has a much broader effect.
    – David Reed
    Commented May 31, 2019 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .