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
ANITHA BEEMUANITHA BEEMU 

can any one please help on Test class :

This is the apex class:
public class CAMRelatedCases 
{
    private final Account acct;
    public CAMRelatedCases(ApexPages.StandardController setCon) 
    {
        this.acct = (Account)setCon.getRecord();
    }
    public List<Case> getmyCaseList()
    {
        myCaseList = [SELECT ID,CaseNumber, CreatedDate, Subject, AccountID, OwnerID, Account.Name, Owner.Name FROM Case WHERE Account.Dealer_of_Record__c = :this.acct.Id];
        Return myCaseList;
    }
    List<Case> myCaseList = [SELECT ID, CaseNumber, AccountID, OwnerID, CreatedDate, Subject, Description, Account.Name, Owner.Name FROM Case LIMIT 4999];
}


and i wrote test class as follows:

@isTest(seealldata = true)
public class CAMRelatedCasesTest 
{
    Static testMethod void CAMRelatedCases()
    {
        //Creating the account for testing
        account a1 = new account(name = 'test'); 
        Insert a1;
        //Creating the Contact w/email
        contact con = new contact(lastname ='testing', firstname = 'testcontact',email='testingit@gmail.com', accountid = a1.Id);
        
        Case cs = new Case(Account = a1, RecordTypeID = '012500000005eVdAAI', Status = 'Open', Origin = 'Inbound Phone Call', Subject = 'testing for apex class', 
                           Description = 'this needs to be a long description', Update_RMA_Task__c = False);
        Insert cs;
        
        CAMRelatedCases.getmyCaseList();
      }
}


Getting Error:Non static method cannot be referenced from a static context: List<Case> CAMRelatedCases.getmyCaseList()

Please can anyone help..
Best Answer chosen by ANITHA BEEMU
AnkaiahAnkaiah (Salesforce Developers) 
Hi Anitha,
Please use the below modifed test class you will get coverage.

@Istest
Private class CAMRelatedCases_Test {
    
   static testMethod void test1(){
        Account acc = new Account();
        acc.name= 'test';
        acc.Type = 'Prospect';
        insert acc;
        
        case c = new case();
        c.subject = 'test case';
        c.Status = 'New';
        c.AccountId = acc.id;
        insert c;
      ApexPages.StandardController sc = new ApexPages.StandardController(acc);
      CAMRelatedCases testAccPlan = new CAMRelatedCases(sc);
      testAccPlan.getmyCaseList();
   
    }
}

If this helps, Please mark it as best answer

Thank you!!!

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Anitha,
Please use the below modifed test class you will get coverage.

@Istest
Private class CAMRelatedCases_Test {
    
   static testMethod void test1(){
        Account acc = new Account();
        acc.name= 'test';
        acc.Type = 'Prospect';
        insert acc;
        
        case c = new case();
        c.subject = 'test case';
        c.Status = 'New';
        c.AccountId = acc.id;
        insert c;
      ApexPages.StandardController sc = new ApexPages.StandardController(acc);
      CAMRelatedCases testAccPlan = new CAMRelatedCases(sc);
      testAccPlan.getmyCaseList();
   
    }
}

If this helps, Please mark it as best answer

Thank you!!!
This was selected as the best answer
ANITHA BEEMUANITHA BEEMU
Thank you so much that worked awesome