You need to sign in to do that
Don't have an account?
NewBee21
apex test class for 100% coverage - Error
Hello,I have written an apex class and now testing the class to achieve 100% code coverage.I have followed the steps as per trailhead but now getting the following error.
@isTest
public Class AccountRelatedCase{
@isTest
public Static void list<Case> lstCases(string Accid){
list<Case> lstCa = [SELECT AccountId,CaseNumber,Subject FROM Case WHERE status = 'New' And AccountId = :Accid];
system.Debug(lstCa);
return lstCa;
}
}
Error:
Unexpected token 'list'.
@isTest
public Class AccountRelatedCase{
@isTest
public Static void list<Case> lstCases(string Accid){
list<Case> lstCa = [SELECT AccountId,CaseNumber,Subject FROM Case WHERE status = 'New' And AccountId = :Accid];
system.Debug(lstCa);
return lstCa;
}
}
Error:
Unexpected token 'list'.
Try BElow Test Class Please Mark It As Best Answer If It Helps
Thank You!
All Answers
your method declaration is incorrect, you cant both declare a method as void and as returning list<Case>
should be -
public Class AccountRelatedCase{
@isTest
public Static list<Case> lstCases(string Accid){
list<Case> lstCa = [SELECT AccountId,CaseNumber,Subject FROM Case WHERE status = 'New' And AccountId = :Accid];
system.Debug(lstCa);
return lstCa;
}
}
Now I am getting an error :"Test methods must have no arguments"
is this right approach to test menthods in apex?
Try BElow Test Class Please Mark It As Best Answer If It Helps
Thank You!