You need to sign in to do that
Don't have an account?
ANITHA 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..
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..
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
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!!!