You need to sign in to do that
Don't have an account?
Clement Debrueres-Bartoli
Test Class for VF page showing Open Cases of Account/Contact
Hi Salesforce fellas,
I have a requirement to create a VF page to display a list of all Cases of the Account, where Status is not "Closed.
My VF page code is
My Apex controller Class is:
But after a lot of attempts I dont manage to create the Test Class for it.
Any idea on how I should create the corresponding Test Class ?
Thank you very much,
Clement
I have a requirement to create a VF page to display a list of all Cases of the Account, where Status is not "Closed.
My VF page code is
<apex:page controller="CustomersOpenCases"> <apex:form > <apex:pageBlock title="Open Cases" id="cases_list"> <apex:repeat value="{!newCases}" var="case" id="case"> <p><apex:outputLink value="/{!case.Id}">{!case.CaseNumber}</apex:outputLink> <apex:outputLink value="/{!case.Id}">{!case.Status}</apex:outputLink></p> </apex:repeat> </apex:pageBlock> </apex:form> </apex:page>
My Apex controller Class is:
public class CustomersOpenCases { public List<Case> getNewCases() { List<Case> results = Database.query( 'SELECT Id, CaseNumber, Status ' + 'FROM Case ' + 'WHERE Status = \'New\' OR Status = \'Reopen\' OR Status = \'Waiting\' ' ); return results; } }
But after a lot of attempts I dont manage to create the Test Class for it.
Any idea on how I should create the corresponding Test Class ?
Thank you very much,
Clement
Try the below test class:
@isTest
public class CustomersOpenCasesTest {
static testMethod void CustomersOpenCasesTestpos ()
{
case cs = new case();
cs.status = 'New';
cs.Origin = 'Phone' ;
// Add your remaining case mandatory Fields.
insert cs;
CustomersOpenCases opencase = new CustomersOpenCases();
opencase.getNewCases();
}
}
Thanks,
Maharajan.C
All Answers
Try the below test class:
@isTest
public class CustomersOpenCasesTest {
static testMethod void CustomersOpenCasesTestpos ()
{
case cs = new case();
cs.status = 'New';
cs.Origin = 'Phone' ;
// Add your remaining case mandatory Fields.
insert cs;
CustomersOpenCases opencase = new CustomersOpenCases();
opencase.getNewCases();
}
}
Thanks,
Maharajan.C
Try this test class: I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi