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.


    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 {

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]; 
    CustomAccountListController controller=new CustomAccountListController(new ApexPages.StandardSetController(accId));



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


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.