You need to sign in to do that
Don't have an account?
Patrick J O'Sullivan
Need help getting code cover from74 to 75 on custom extension class
Hi Guys,
I've written my first Extension class to use within a VF override on my custom key account synopsis object...
I'm stuck at 74% coverage can you guys take a look and see if you can spot what will bring it above the threshold please? getting a bit desperate
I've written my first Extension class to use within a VF override on my custom key account synopsis object...
I'm stuck at 74% coverage can you guys take a look and see if you can spot what will bring it above the threshold please? getting a bit desperate
public class KAMKAPextension { private final Key_Account_Overview__c KAP; List<Kam_Plan_Actions__c> overdue; List<Kam_Plan_Actions__c> next30days; List<Kam_Plan_Actions__c> from30to60days; List<Kam_Plan_Actions__c> from60to90days; List<Kam_Plan_Actions__c> longterm; List<Kam_Plan_actions__c> Completed; List<Kam_Plan_actions__c> cancelled; list<Kam_Plan_actions__c> KamToday; //Method for new Child Kam Plan Action goes here public KAMKAPextension(ApexPages.StandardController KAPController) { this.KAP = (Key_Account_Overview__c)KAPController.getRecord(); } Public list<Kam_Plan_Actions__c> getoverdue() { If (overdue == null) { overdue = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE due_date__c < TODAY AND Status__c !='Complete' AND Status__c !='Cancelled' AND Key_Account_Synopsis__c = :KAP.id]; } return overdue; } Public list<Kam_Plan_Actions__c> getKamToday() { If (KamToday == null) { KamToday = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE due_date__c = NEXT_N_DAYS:29 AND Status__c !='Complete' AND Status__c !='Cancelled' AND Key_Account_Synopsis__c =:KAP.id]; } return KamToday; } Public list<Kam_Plan_Actions__c> getnext30days() { If (next30days == null) { next30days = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE due_date__c >= TODAY AND due_date__c = NEXT_N_DAYS:29 AND Status__c !='Complete' AND Status__c !='Cancelled' AND Key_Account_Synopsis__c =:KAP.id]; } return next30days; } Public list<Kam_Plan_Actions__c> getfrom30to60days() { If (from30to60days == null) { from30to60days = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE due_date__c !=NEXT_N_DAYS:29 AND due_date__c = NEXT_N_DAYS:59 AND Status__c !='Complete' AND Status__c !='Cancelled' AND Key_Account_Synopsis__c = :KAP.id]; } return from30to60days; } Public list<Kam_Plan_Actions__c> getfrom60to90days() { If (from60to90days == null) { from60to90days = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE due_date__c !=NEXT_N_DAYS:59 AND due_date__c = NEXT_N_DAYS:89 AND Status__c !='Complete' AND Status__c !='Cancelled' AND Key_Account_Synopsis__c = :KAP.id]; } return from60to90days; } Public list<Kam_Plan_Actions__c> getlongterm() { If (longterm == null) { longterm = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE due_date__c > TODAY AND due_date__c != TODAY AND due_date__c !=NEXT_N_DAYS:89 AND Status__c !='Complete' AND Status__c !='Cancelled' AND Key_Account_Synopsis__c = :KAP.id]; } return longterm; } Public list<Kam_Plan_Actions__c> getCompleted() { If (Completed == null) { Completed = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE due_date__c >NEXT_N_DAYS:89 AND Status__c ='Complete'AND Key_Account_Synopsis__c = :KAP.id]; } return Completed; } Public list<Kam_Plan_Actions__c> getcancelled() { If (cancelled == null) { cancelled = [ SELECT Id, Name, Status__c, Due_Date__c FROM Kam_Plan_Actions__c WHERE Status__c ='Completed' AND Key_Account_Synopsis__c =:KAP.id ]; } return cancelled; } }
You'll want to test all methods and all conditions. This means you're looking at several test methods, proably two or more for each method in KAMKAP extension. You're class doesn't look too complicated here, so you're likely missing a method on your unit test. Not only do you need to get your code coverage to 75%, but you should strive for 100% code coverage, which looks achievable given the above code snippet.