You need to sign in to do that
Don't have an account?
Neel88
Test class for dynamic soql/VF page
Hi Experts,
I have this class to query records and display the results in a VF page. I need help to write a test class for this. Will be my first. Please advice
public with sharing class scbilling { string sID = ApexPages.currentPage().getParameters().get('id'); //
public Date T1 {get;set;}
public Date T2 {get;set;}
integer monthly =0;
integer totalpayment=0;
integer mCount=0;
Date Tx; //Date Tx = Date.newInstance(2015,1,1);
public Pagereference doIt() {
totalpayment=0; displayResults.Clear(); mcount=0; return null;}//For action button
public scontract__c sc = [select System__r.name, System_Live_Date__c, First_Month_End_of_Service__c from scontract__c where id=:sID]; public scontract__c getSc(){ return sc; }
public LIST<AggregateResult> mp = new LIST<AggregateResult>();//get results from SOQL Map<Date, Integer> displayResults = new Map<Date, Integer>(); //To store Date and Monthly
Public integer getcalc(){
IF(T1==null) Tx= sc.First_Month_End_of_Service__c; else Tx=T1; //date.newInstance(2017,1,1);//when page loads
Tx = Tx.addMonths(1); //Move to next month of T1 Tx = Tx.toStartOfMonth(); //Get to 1st date of the month of T1 + 1 month Tx = Tx.addDays(-1);//Get last date of the month of T1
IF(T2==null) T2= Date.TODAY(); IF(T2 > Tx.addMonths(60)) T2=T2.addmonths(60);//to limit the loops to 60 While (Tx <= T2){//loop for x months between T1 & T2
mp = [select sum(monthly_fee__c) cmp from scontract_item__c where s_contract__c=:sID AND First_Month_End_of_Service_Period__c <=:Tx AND last_month_end_of_service__c >= :Tx];
monthly = integer.valueOf(mp[0].get('cmp')); //convert aggregate value to integer
IF(monthly==null) monthly=0; // else monthly=monthly;
totalPayment = totalPayment + monthly;
displayResults.put(Tx, monthly); //insert values into map
Tx = Tx.addMonths(1);
mCount = mCount+1;
IF(mCount >=60) break;
}
return totalPayment ; }
Public Map<date, integer> getdisplayResults(){return displayResults;} //sends map values to VF page
public Void clear(){displayResults.clear();
}
public integer getmCount(){return mcount;}
}
I have this class to query records and display the results in a VF page. I need help to write a test class for this. Will be my first. Please advice
public with sharing class scbilling { string sID = ApexPages.currentPage().getParameters().get('id'); //
public Date T1 {get;set;}
public Date T2 {get;set;}
integer monthly =0;
integer totalpayment=0;
integer mCount=0;
Date Tx; //Date Tx = Date.newInstance(2015,1,1);
public Pagereference doIt() {
totalpayment=0; displayResults.Clear(); mcount=0; return null;}//For action button
public scontract__c sc = [select System__r.name, System_Live_Date__c, First_Month_End_of_Service__c from scontract__c where id=:sID]; public scontract__c getSc(){ return sc; }
public LIST<AggregateResult> mp = new LIST<AggregateResult>();//get results from SOQL Map<Date, Integer> displayResults = new Map<Date, Integer>(); //To store Date and Monthly
Public integer getcalc(){
IF(T1==null) Tx= sc.First_Month_End_of_Service__c; else Tx=T1; //date.newInstance(2017,1,1);//when page loads
Tx = Tx.addMonths(1); //Move to next month of T1 Tx = Tx.toStartOfMonth(); //Get to 1st date of the month of T1 + 1 month Tx = Tx.addDays(-1);//Get last date of the month of T1
IF(T2==null) T2= Date.TODAY(); IF(T2 > Tx.addMonths(60)) T2=T2.addmonths(60);//to limit the loops to 60 While (Tx <= T2){//loop for x months between T1 & T2
mp = [select sum(monthly_fee__c) cmp from scontract_item__c where s_contract__c=:sID AND First_Month_End_of_Service_Period__c <=:Tx AND last_month_end_of_service__c >= :Tx];
monthly = integer.valueOf(mp[0].get('cmp')); //convert aggregate value to integer
IF(monthly==null) monthly=0; // else monthly=monthly;
totalPayment = totalPayment + monthly;
displayResults.put(Tx, monthly); //insert values into map
Tx = Tx.addMonths(1);
mCount = mCount+1;
IF(mCount >=60) break;
}
return totalPayment ; }
Public Map<date, integer> getdisplayResults(){return displayResults;} //sends map values to VF page
public Void clear(){displayResults.clear();
}
public integer getmCount(){return mcount;}
}