I'm creating a visualforce page for a Dashboard component. In the controller I have a wrapper class and in one of the methods I return a map of a list of the wrapper records. Example trimmed down:

public static Map<String, List<dashData>> makeDashMap(List<CampaignMember> memberList, List<Idea_Dashboard_Campaign__mdt> campList)
    Map<String, List<dashData>> dashMap = new Map<String, List<dashData>>();
    for(CampaignMember cm : memberList)
        dashData d = new dashData();
        d.paName = cm.Contact.Idea_Practice__c;
        d.campaign1 = 0;
        d.campaign2 = 0;

            dashMap.put(d.paName, new List<dashData>{d});
        } else {
    return dashMap;

// Wrapper class
@testVisible public class dashData 
    public String paName {get; set;}
    public Integer campaign1 {get; set;}
    public Integer campaign2 {get; set;}
    public Integer variance {get; set;} 

I can't compile my test method because I can't figure out the correct syntax to reference the wrapper but a list of the wrapper records. Example:

static void testMakeDashMap()
    List<CampaignMember> memberList = [       
        SELECT  Id,
        FROM    CampaignMember];

    List<Idea_Dashboard_Campaign__mdt> campList = [
        SELECT  MasterLabel,
        FROM    Idea_Dashboard_Campaign__mdt
        ORDER BY Campaign_Order__c ASC];

        NPD_IdeaDashboardController.dashData dashData = new NPD_IdeaDashboardController.dashData();
        Map<String, List<dashData>> results = NPD_IdeaDashboardController.makeDashMap(memberList, campList);

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

I get the error on the result line:

Invalid type: dashData

How can I get the results of the map so I can try and assert that it comes back as expected?

  • is the outer class named NPD_IdeaDashboardController ? Jul 12 '19 at 16:45
  • Yes. That's the main class name. Jul 12 '19 at 16:51

It looks like the issue is on this line

 Map<String, List<dashData>> results = NPD_IdeaDashboardController.makeDashMap(memberList, campList);

There is no dashDatain local namespace, its innerclash so you have to refer it as

Map<String, List<NPD_IdeaDashboardController.dashData>> results = NPD_IdeaDashboardController.makeDashMap(memberList, campList);
  • Do I still need the line above it then? The NPD_IdeaDashboardController.dashData dashData = new NPD_IdeaDashboardController.dashData(); Jul 12 '19 at 17:25
  • @DanWooding yes you have to. There is no import statements in apex that will ensure the dataDash you are referring is the correct one Jul 12 '19 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.