You need to sign in to do that
Don't have an account?
Clement Debrueres-Bartoli
Test Class for VF page showing Current Cases of the Account
Hi Salesforce friends,
I am still a beginner with Apex class and I have a requirement to create a VF page showing all the open cases of the Acount.
My VF page is
But I dont manage to create a proper Test Class, after a lot of attempts.
Any good soul who could help me with that test Class?
Thank you very much
I am still a beginner with Apex class and I have a requirement to create a VF page showing all the open cases of the Acount.
My VF page is
<apex:page standardController="Case" extensions="ShowCustomersOpenCases"> <apex:form > <apex:pageBlock > <apex:pageBlockTable value="{!CA}" var="C" columnsWidth="1%,1%,1%" > <apex:column headerValue="Case Number" > <apex:commandLink value="{!C.CaseNumber}" action="/{!C.Id}" target="_blank" /> </apex:column> <apex:column headerValue="Status" value="{!C.Status}" /> <apex:column headerValue="Created Date" value="{!C.CreatedDate}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>My Apex Controller is
public with sharing class ShowCustomersOpenCases { public List<Case> CA { get; private set; } public ShowCustomersOpenCases(ApexPages.StandardController controller) { controller.addFields(new List<String>{ 'AccountId' }); Case currentCase = (Case)controller.getRecord(); CA = [Select Id, CaseNumber, CreatedDate, Status, Subject, ContactId FROM Case Where Status <> 'Closed' AND AccountId = :currentCase.AccountId and Id != :currentCase.Id Order by CreatedDate DESC Limit 100]; } }
But I dont manage to create a proper Test Class, after a lot of attempts.
Any good soul who could help me with that test Class?
Thank you very much
first of all thank you for your answer.
Unfortunately, I slightly modified your code to adapt to my environment, but it fails when I run the test, although I havent modified the elements of your code
Error message is: System.DMLException: Insert failed. First Exception on row 0; first error: Class.ShowCustomersOpenCasesTest.testCase: line 18, column 1.
Any idea on how this fails?
Thank you very much,
Clement
I double checked everything and made sure the fields that I create are correct, like this:
However the code coverage is only 40% (2/5) and the Test doesnt fully pass to show green check.
Any idea on how I can fix this maybe?
Thank you for your help
Clement