You need to sign in to do that
Don't have an account?
Becky Miller 15
Test Class Improvements
I am not sure what I am doing wrong in creating this Test Class. It creates the row correctly but my concern is that I am hardcoding a few of the IDs in the Test Class:
Apex Code:
public with sharing class BpQuotaQtr {
private ApexPages.StandardController c;
public List <Quota__c> quotas {get;set;}
public List <Business_Plan__c> bp {get;set;}
public List <Period> period {get;set;}
Integer FiscalYearStartMonth =
[select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;
String TodaysDate = date.today().format();
// Get information about the Quota being worked on
// Needs to be based on Business Plan per Person
// Need to get the correct FY and Correct Quarter based on todays date.
//
public BpQuotaQtr(ApexPages.StandardController controller) {
String strFY = '';
Id bpid1;
business_plan__c bp = (business_plan__c)controller.getRecord();
List <Period> Periods = [Select p.Number From Period p Where (p.StartDate <= TODAY AND p.EndDate >= TODAY) and p.type = 'Quarter' Limit 1];
List <business_plan__c> bpid = [Select id From business_plan__c bp where (bp.Start_Date__c <= TODAY AND bp.End_Date__c >= TODAY) LIMIT 1];
if(!Periods.isEmpty())
{
/* you have applied LIMIT 1 which means only one record will be retrieved */
strFY = String.valueOf(Periods[0].Number);
bpid1 = bpid[0].id;
}
system.debug('*****bpid1*******'+bpid1);
system.debug('*******strFY *****'+strFY);
quotas = [SELECT Actual_Sales__c, Actual_vs_Quota__c, Annual_Actual_Sales__c, Annual_Quota__c, Label_Actual_Sales__c, Label_Sales_Won__c,
Annual_Targeted_New_Bus_Sale__c, Business_Plan__c, Fiscal_Period2__c,
Quota__c, Sales_Categories__c, Sales_Category_Name__c, Sales_Needed_to_Hit_Quota2__c,Sales_Product_Category__c,
Sales_Won__c,Target_vs_Quota__c,Targeted_New_Business_Sales__c
FROM Quota__c WHERE ((Start_Date__c = THIS_FISCAL_QUARTER AND End_Date__c = THIS_FISCAL_QUARTER) AND
Period__c = True AND
business_Plan__c =:bp.id
)
ORDER BY Sales_Category_Name__c ];
}
Visualforce Code:
<apex:page standardController="Business_Plan__c" extensions="BpQuotaQtr" tabStyle="Quota__c">
<apex:form >
<apex:pageBlock title="Current Quarterly Breakout">
<style>
body .bPageBlock .pbBody .blue .pbSubheader{
background-color:#0000cc;
}
body .bPageBlock .pbBody .grey .pbSubheader{
background-color:#c0c0c0;
}
body .bPageBlock .pbBody .grey .pbSubheader h3{
color:#000;
}
</style>
<apex:outputPanel styleClass="blue" layout="block">
<apex:pageBlockSection title="Sales Categories Sales and Quarterly Breakout">
</apex:pageBlockSection>
</apex:outputPanel>
<apex:pageBlockTable value="{!quotas}" var="q" >
<apex:column headerClass="headerStyle"/>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Sales_Category_Name__c.Label}" value="{!q.Sales_Category_Name__c }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Quota__c.Label}" value="{!q.Quota__c }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Fiscal_Period2__c.Label}" value="{!q.Fiscal_Period2__c }" > </apex:column>
<apex:variable value="{!q.Label_Actual_Sales__c}" var="h1"/>
<apex:column headerValue="{!h1}" value="{!q.Actual_Sales__c}" >
</apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Actual_vs_Quota__c.Label}" value="{!q.Actual_vs_Quota__c}"
style="{!If((q.Actual_vs_Quota__c)< 85,'font-size:15px; font-weight:bold;color:red',
If((q.Actual_vs_Quota__c)> 100,'font-size:15px; font-weight:bold;color:green ','color:black')) }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Sales_Needed_to_Hit_Quota2__c.Label}" value="{!q.Sales_Needed_to_Hit_Quota2__c}" > </apex:column>
<apex:variable value="{!q.Label_Sales_Won__c}" var="h2"/>
<apex:column headerValue="{!h2}" value="{!q.Sales_Won__c}" >
</apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Targeted_New_Business_Sales__c.Label}" value="{!q.Targeted_New_Business_Sales__c }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Target_vs_Quota__c.Label}" value="{!q.Target_vs_Quota__c}"
style="{!If((q.Target_vs_Quota__c)< 85,'font-size:15px; font-weight:bold;color:red',
If((q.Target_vs_Quota__c)> 100,'font-size:15px; font-weight:bold;color:green ','color:black')) }" > </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Test Class:
@isTest
private class BpQuotaQtrTest {
private static final Id id = Schema.SObjectType.quota__c.getRecordTypeInfosByName().get('US Endo Sales').getRecordTypeId();
private static final Id bpcid = Schema.SObjectType.business_plan__c.getRecordTypeInfosByName().get('Capital').getRecordTypeId();
private static final Id bppid = Schema.SObjectType.business_plan__c.getRecordTypeInfosByName().get('Procedural').getRecordTypeId();
@isTest static void BpQuotaQtrTest() {
Quota__c qta = new Quota__c();
qta.Actual_Sales__c = 10000;
qta.quota__c = 1000000;
qta.Annual_Actual_Sales__c = 300000;
qta.Annual_Quota__c = 10000000;
qta.Annual_Targeted_New_Bus_Sale__c = 300000;
qta.Business_Plan__c = 'a3I0P000000Cw8a';
qta.Fiscal_Period2__c = 'Q2';
qta.Quota__c = 250000;
qta.Sales_Categories__c = 'a5f0P000000Pfr6';
qta.Sales_Won__c = 2500;
qta.Targeted_New_Business_Sales__c = 3400;
insert qta;
Test.setCurrentPage(Page.BpQuotaQtr);
}
}
Apex Code:
public with sharing class BpQuotaQtr {
private ApexPages.StandardController c;
public List <Quota__c> quotas {get;set;}
public List <Business_Plan__c> bp {get;set;}
public List <Period> period {get;set;}
Integer FiscalYearStartMonth =
[select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;
String TodaysDate = date.today().format();
// Get information about the Quota being worked on
// Needs to be based on Business Plan per Person
// Need to get the correct FY and Correct Quarter based on todays date.
//
public BpQuotaQtr(ApexPages.StandardController controller) {
String strFY = '';
Id bpid1;
business_plan__c bp = (business_plan__c)controller.getRecord();
List <Period> Periods = [Select p.Number From Period p Where (p.StartDate <= TODAY AND p.EndDate >= TODAY) and p.type = 'Quarter' Limit 1];
List <business_plan__c> bpid = [Select id From business_plan__c bp where (bp.Start_Date__c <= TODAY AND bp.End_Date__c >= TODAY) LIMIT 1];
if(!Periods.isEmpty())
{
/* you have applied LIMIT 1 which means only one record will be retrieved */
strFY = String.valueOf(Periods[0].Number);
bpid1 = bpid[0].id;
}
system.debug('*****bpid1*******'+bpid1);
system.debug('*******strFY *****'+strFY);
quotas = [SELECT Actual_Sales__c, Actual_vs_Quota__c, Annual_Actual_Sales__c, Annual_Quota__c, Label_Actual_Sales__c, Label_Sales_Won__c,
Annual_Targeted_New_Bus_Sale__c, Business_Plan__c, Fiscal_Period2__c,
Quota__c, Sales_Categories__c, Sales_Category_Name__c, Sales_Needed_to_Hit_Quota2__c,Sales_Product_Category__c,
Sales_Won__c,Target_vs_Quota__c,Targeted_New_Business_Sales__c
FROM Quota__c WHERE ((Start_Date__c = THIS_FISCAL_QUARTER AND End_Date__c = THIS_FISCAL_QUARTER) AND
Period__c = True AND
business_Plan__c =:bp.id
)
ORDER BY Sales_Category_Name__c ];
}
Visualforce Code:
<apex:page standardController="Business_Plan__c" extensions="BpQuotaQtr" tabStyle="Quota__c">
<apex:form >
<apex:pageBlock title="Current Quarterly Breakout">
<style>
body .bPageBlock .pbBody .blue .pbSubheader{
background-color:#0000cc;
}
body .bPageBlock .pbBody .grey .pbSubheader{
background-color:#c0c0c0;
}
body .bPageBlock .pbBody .grey .pbSubheader h3{
color:#000;
}
</style>
<apex:outputPanel styleClass="blue" layout="block">
<apex:pageBlockSection title="Sales Categories Sales and Quarterly Breakout">
</apex:pageBlockSection>
</apex:outputPanel>
<apex:pageBlockTable value="{!quotas}" var="q" >
<apex:column headerClass="headerStyle"/>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Sales_Category_Name__c.Label}" value="{!q.Sales_Category_Name__c }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Quota__c.Label}" value="{!q.Quota__c }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Fiscal_Period2__c.Label}" value="{!q.Fiscal_Period2__c }" > </apex:column>
<apex:variable value="{!q.Label_Actual_Sales__c}" var="h1"/>
<apex:column headerValue="{!h1}" value="{!q.Actual_Sales__c}" >
</apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Actual_vs_Quota__c.Label}" value="{!q.Actual_vs_Quota__c}"
style="{!If((q.Actual_vs_Quota__c)< 85,'font-size:15px; font-weight:bold;color:red',
If((q.Actual_vs_Quota__c)> 100,'font-size:15px; font-weight:bold;color:green ','color:black')) }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Sales_Needed_to_Hit_Quota2__c.Label}" value="{!q.Sales_Needed_to_Hit_Quota2__c}" > </apex:column>
<apex:variable value="{!q.Label_Sales_Won__c}" var="h2"/>
<apex:column headerValue="{!h2}" value="{!q.Sales_Won__c}" >
</apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Targeted_New_Business_Sales__c.Label}" value="{!q.Targeted_New_Business_Sales__c }" > </apex:column>
<apex:column headerValue="{!$ObjectType.Quota__c.Fields.Target_vs_Quota__c.Label}" value="{!q.Target_vs_Quota__c}"
style="{!If((q.Target_vs_Quota__c)< 85,'font-size:15px; font-weight:bold;color:red',
If((q.Target_vs_Quota__c)> 100,'font-size:15px; font-weight:bold;color:green ','color:black')) }" > </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Test Class:
@isTest
private class BpQuotaQtrTest {
private static final Id id = Schema.SObjectType.quota__c.getRecordTypeInfosByName().get('US Endo Sales').getRecordTypeId();
private static final Id bpcid = Schema.SObjectType.business_plan__c.getRecordTypeInfosByName().get('Capital').getRecordTypeId();
private static final Id bppid = Schema.SObjectType.business_plan__c.getRecordTypeInfosByName().get('Procedural').getRecordTypeId();
@isTest static void BpQuotaQtrTest() {
Quota__c qta = new Quota__c();
qta.Actual_Sales__c = 10000;
qta.quota__c = 1000000;
qta.Annual_Actual_Sales__c = 300000;
qta.Annual_Quota__c = 10000000;
qta.Annual_Targeted_New_Bus_Sale__c = 300000;
qta.Business_Plan__c = 'a3I0P000000Cw8a';
qta.Fiscal_Period2__c = 'Q2';
qta.Quota__c = 250000;
qta.Sales_Categories__c = 'a5f0P000000Pfr6';
qta.Sales_Won__c = 2500;
qta.Targeted_New_Business_Sales__c = 3400;
insert qta;
Test.setCurrentPage(Page.BpQuotaQtr);
}
}