0

Creating a real simple test class here to try and get coverage of my getAccounts() method. Everything I have tried has not worked. Getting the classic non static method cannot be referenced from a static context error.

Controller:

    public class CustomAccountListController {
   
   public CustomAccountListController(ApexPages.StandardSetController ctrl) {
    setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
            [Select Id, Name, AV_Description__c, BillingCity, BillingState, AV_Points__c, Growth_Indicators__c, Capital_Raised__c, NumberOfEmployees, AV_Founded__c, Status__c, Deal_Lead__c, Outreach_Email_Count__c, Most_Recent_Outreach_Date__c FROM Account WHERE Status__c = 'Lead-New' ORDER BY AV_Points__c Desc]));
  }  
    
 public ApexPages.StandardSetController setCon { get; set; }

    // Initialize setCon and return a list of records
    public List<Account> getAccounts() {
        return (List<Account>) setCon.getRecords();
    }
}

Test class:

@isTest public class CustomAccountListControllerTest {

    @testSetup
public static void setup(){
    
    Account acc = new Account();
    acc.Name = 'Test Account';
    insert acc;
    
    
}
@isTest static void testMethod1(){
  List<Account> accId = [Select Id from Account Limit 1]; 
    test.startTest();
    CustomAccountListController controller=new CustomAccountListController(new ApexPages.StandardSetController(accId));
    CustomAccountListController.getAccounts();
   test.stopTest();
    
}

}

1 Answer 1

2

You need to call the method on the instance you've created:

controller.getAccounts();

You must log in to answer this question.

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