I have created Apex Class, followed by test class and a vf page related to Apex Class. Now every time I am deploying I am getting the error message. Please suggest and let me know how to make the deployment successful.
Deploy Results: File Name: classes/ResourceBillRate.cls Full Name: ResourceBillRate Action: UPDATED Result: SUCCESS
Problem: n/a
File Name: classes/testResourceBillRate.cls Full Name: testResourceBillRate Action: UPDATED Result: SUCCESS
Problem: n/aFile Name: package.xml Full Name: package.xml Action: UPDATED Result: SUCCESS Problem: n/a
File Name: pages/VF_ResrouceBillRate.page Full Name: VF_ResrouceBillRate Action: UPDATED Result: SUCCESS
Problem: n/aTest Results:
Run Failures: testResourceBillRate.myUnitTest System.DmlException: Update failed. First exception on row 0 with id a0I9000000FllpCEAR; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trg_CalculateHours: execution of BeforeUpdate
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
Trigger.trg_CalculateHours: line 37, column 1: []
testResourceBillRate.myUnitTest1 System.DmlException: Update failed. First exception on row 0 with id a0I9000000FllpDEAR; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, trg_CalculateHours: execution of BeforeUpdatecaused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
Trigger.trg_CalculateHours: line 37, column 1: []
testTrgAgencyInfoUpdate.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Vendor selected above does not belongs to this Project.: [Project_ID__c]
testTrgUpdateCost.myUnitTest System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Vendor selected above does not belongs to this Project.: [Project_ID__c]
testTrgUpdateCost.myUnitTest2 System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Vendor selected above does not belongs to this Project.: [Project_ID__c]
testTrgUpdateCost.myUnitTest44 System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Vendor selected above does not belongs to this Project.: [Project_ID__c]
Average test coverage across all Apex Classes and Triggers is 73%, at least 75% test coverage is required.
ResourceBillRate.cls
public with sharing class ResourceBillRate{
/* Properties and public variables*/
public ID StartsheetID;
Public Date pTo;
Public Date pFrom;
public boolean bIsGenerated;
List<Timecard_Entries__c> tCard = new List<Timecard_Entries__c>();
List<Resource_Bill_Rate__c> rscBillRate = new List<Resource_Bill_Rate__c>();
List<Billing_Repository__c> rscAgencyRate = new List<Billing_Repository__c>();
public List<wrapperInvoiceDetails> lstWrpInvDtl{get;set;}
String parentId = ApexPages.currentPage().getParameters().get('id');
string sRecordType;
RecordType objRT = new RecordType();
public Generate_Invoice__c gInvoice{get;set;}
public ApexPages.StandardSetController standardController;
public boolean bIsDispAmount{get;set;}
public decimal dTotalAmount{get;set;}
public string sBillingRate{get;set;}
public integer StandardHours;
public ResourceBillRate(ApexPages.StandardSetController standardController){
this.standardController = standardController;
}
public ResourceBillRate(ApexPages.StandardController controller)
{
system.debug('*********************************ResourceBillRateCalled : ');
lstWrpInvDtl = new List<wrapperInvoiceDetails>();
gInvoice = [select RecordType.Name,Project_ID__c,Project_ID__r.Billing_Rate__c,Period_From__c,Period_To__c,Invoice_Generated__c,Consultant__c from Generate_Invoice__c where id=:parentId];
bIsGenerated = gInvoice.Invoice_Generated__c ;
StartsheetID = gInvoice.Project_ID__c;
pFrom = gInvoice.Period_From__c;
pTo = gInvoice.Period_To__c;
sRecordType = gInvoice.RecordType.Name;
sBillingRate = gInvoice.Project_ID__r.Billing_Rate__c;
system.debug('*********************************gInvoice : '+gInvoice);
system.debug('*********************************StartsheetID : '+StartsheetID);
//RscBillRate();
}
public void RscBillRate()
{
/*rscBillRate = [Select Name,Bill_Rate__c,Bill_Type__c,Project_ID__r.Name,Resource_Name__c,Total_Billable_Hours__c,
fml_Period_From__c,Period_From_new__c,Period_To__c from Resource_Bill_Rate__c where
Project_ID__c=:StartsheetID and Period_From_new__c>=:pFrom and Period_To__c<=:pTo
order by createdDate Asc]; */
List<TimeCard__c> lstTC = [Select id ,Project_ID__c,Period_From__c,Period_To__c from TimeCard__c where Project_ID__c =:StartsheetID ];
tCard = [SELECT Date__c,Hours__c,Project_ID__c, Invoice_Generated__c, TimeCard__c FROM Timecard_Entries__c WHERE Project_ID__c
=:StartsheetID and Date__c >=:pFrom and Date__c <=:pTo];
if(sRecordType == 'Agency Invoice')
{
AgencyBilling(lstTC);
}
if(sRecordType == 'Consulting Invoice')
{
ConsultingBilling(lstTC);
}
}
public void MonthlyStandardHours()
{
date ob = date.today();
integer iYear = ob.year();
integer iMonth = ob.month();
List<US_Calender_Yearly__c>lstY = [Select id,Standard_Hours__c from US_Calender_Yearly__c where Month_Number__c =:iMonth and US_Calender_Yearly__r.Year__c =:iYear];
StandardHours = integer.valueof(lstY[0].Standard_Hours__c);
}
private void AgencyBilling(List<TimeCard__c> lstTC)
{
MonthlyStandardHours();
//lstWrpInvDtl = new List<wrapperInvoiceDetails>();
if(sBillingRate == 'Monthly' && bIsGenerated == false)
{
bIsDispAmount = true;
}
else
{
bIsDispAmount = false;
}
rscAgencyRate = [SELECT To_Date__c,From_Date__c,Total_Billable_Hours__c,Customer_Billing__r.Startsheet__r.Resource__r.Name,Customer_Billing__r.Startsheet__r.Billing_Rate__c,Agency_Rate_Hour__c, Agency_Rate_Month__c, Name,Current_Hourly_Billing_Rate__c,Current_Monthly_Billing_Rate__c,Customer_Billing__c,Effective_Bill_Date__c, Employee_Annual_Salary__c, GP_Rate__c, Hourly_Cost__c,Id
FROM Billing_Repository__c where Customer_Billing__r.Startsheet__c =:StartsheetID and From_Date__c >=: pFrom
order by createdDate Asc];
system.debug('++++++tCard+++++++'+tCard.size());
for(integer i=0;i<rscAgencyRate.size();i++)
{
rscAgencyRate[i].Total_Billable_Hours__c = 0;
for(integer k=0;k<tCard.size();k++)
{
if(tCard[k].Date__c <= rscAgencyRate[i].To_Date__c && tCard[k].Date__c>=rscAgencyRate[i].From_Date__c)
{
rscAgencyRate[i].Total_Billable_Hours__c = rscAgencyRate[i].Total_Billable_Hours__c + tCard[k].Hours__c ;
}
}
//rscAgencyRate[i].From_Date__c = lstTC[0].Period_From__c;
//rscAgencyRate[i].To_Date__c = lstTC[0].Period_To__c ;
}
system.debug('++++++rscAgencyRate+++++++'+rscAgencyRate);
if(bIsGenerated)
{
system.debug('++++++bIsGenerated+++++++'+bIsGenerated);
List<Invoice_Details__c> lstInvDtls = [Select id,Amount__c,From__c,Generate_Invoice__c,Hours__c,Rate__c,Rate_Type__c,Resource_Name__c,To_Date__c from Invoice_Details__c where Generate_Invoice__c =: parentId];
List<Invoice_Details__c> lstInvDtlsTest = [Select id,Amount__c,From__c,Generate_Invoice__c,Hours__c,Rate__c,Rate_Type__c,Resource_Name__c,To_Date__c from Invoice_Details__c ];
system.debug('parent id >'+parentId);
system.debug('+++lstInvDtlsTest >+++'+ lstInvDtlsTest );
if(lstInvDtls.size()<=0)
{
//Save record in invoice detail
List<Invoice_Details__c> lstInsrtInvDtl = new List<Invoice_Details__c>();
system.debug('++++++rscAgencyRate.size()+++++++'+rscAgencyRate.size());
for(integer i=0;i<rscAgencyRate.size();i++)
{
wrapperInvoiceDetails obj = new wrapperInvoiceDetails(rscAgencyRate[i]);
lstWrpInvDtl.add(obj);
if(sBillingRate == 'Monthly')
{
lstWrpInvDtl[i].Amount = (lstWrpInvDtl[i].Rate/StandardHours)* lstWrpInvDtl[i].Hours;
}
if(sBillingRate == 'Hourly')
{
lstWrpInvDtl[i].Amount = lstWrpInvDtl[i].Rate * lstWrpInvDtl[i].Hours ;
}
Invoice_Details__c objInv = new Invoice_Details__c();
objInv.Generate_Invoice__c = parentId ;
objInv.Amount__c = obj.Amount;
objInv.Hours__c = obj.Hours;
objInv.Rate__c = obj.Rate;
objInv.Rate_Type__c = obj.RateType;
objInv.To_Date__c = obj.ToDate;
objInv.From__c = obj.FromDate;
objInv.Resource_Name__c = obj.ResourceName ;
lstInsrtInvDtl.add(objInv);
}
system.debug('++++++lstInsrtInvDtl+++++++'+lstInsrtInvDtl);
insert lstInsrtInvDtl;
}
else
{
system.debug('++++++lstInvDtls.size()+++++++'+lstInvDtls.size());
//get data from invoice details
for(integer i=0;i<lstInvDtls.size();i++)
{
wrapperInvoiceDetails obj = new wrapperInvoiceDetails(lstInvDtls[i]);
lstWrpInvDtl.add(obj);
}
}
}
else
{
system.debug('++++++rscAgencyRate.size()+++++++'+rscAgencyRate.size());
for(integer i=0;i<rscAgencyRate.size();i++)
{
wrapperInvoiceDetails obj = new wrapperInvoiceDetails(rscAgencyRate[i]);
lstWrpInvDtl.add(obj);
system.debug('++++++sBillingRate+++++++'+sBillingRate);
if(sBillingRate == 'Monthly')
{
//lstWrpInvDtl[0].Amount = lstWrpInvDtl[0].Amount__c;
lstWrpInvDtl[i].Amount = (lstWrpInvDtl[i].Rate/StandardHours)* lstWrpInvDtl[i].Hours;
system.debug('++++++lstWrpInvDtl[i].Amount+++++++'+lstWrpInvDtl[i].Amount);
}
if(sBillingRate == 'Hourly')
{
lstWrpInvDtl[i].Amount = lstWrpInvDtl[i].Rate * lstWrpInvDtl[i].Hours ;
system.debug('++++++lstWrpInvDtl[i].Amount+++++++'+lstWrpInvDtl[i].Amount);
system.debug('++++++lstWrpInvDtl[i].Hours+++++++'+lstWrpInvDtl[i].Hours);
}
}
}
//Fill Total Amount
dTotalAmount = lstWrpInvDtl[0].Amount ;
}
public void UpdateAgencyTotalAmount()
{
lstWrpInvDtl[0].Amount = dTotalAmount ;
List<Invoice_Details__c> lstInvDtls = [Select id from Invoice_Details__c where Generate_Invoice__c =: parentId];
List<Invoice_Details__c>lstInsrtInvDtl2 = new List<Invoice_Details__c>();
for(integer i=0;i<lstWrpInvDtl.size();i++)
{
//wrapperInvoiceDetails obj = new wrapperInvoiceDetails(rscBillRate[i]);
//lstWrpInvDtl.add(obj);
Invoice_Details__c objInv = new Invoice_Details__c();
objInv.id = lstInvDtls[0].id;
objInv.Generate_Invoice__c = parentId ;
objInv.Amount__c = dTotalAmount ;
objInv.Hours__c = lstWrpInvDtl[0].Hours;
objInv.Rate__c = lstWrpInvDtl[0].Rate;
objInv.Rate_Type__c = lstWrpInvDtl[0].RateType;
objInv.To_Date__c = lstWrpInvDtl[0].ToDate;
objInv.From__c = lstWrpInvDtl[0].FromDate;
objInv.Resource_Name__c = lstWrpInvDtl[0].ResourceName ;
lstInsrtInvDtl2.add(objInv);
}
update lstInsrtInvDtl2;
}
private void ConsultingBilling(List<TimeCard__c> lstTC)
{
MonthlyStandardHours();
rscBillRate = [Select Resource__r.Name,Name,Bill_Rate__c,Bill_Type_New__c,Project_ID__r.Name,Resource_Name__c,Total_Billable_Hours__c,
fml_Period_From__c,Period_From_new__c,Period_To__c,Project_ID__r.Billing_Rate__c,Project_ID__r.Standard_Hours__c from Resource_Bill_Rate__c where
Project_ID__c=:StartsheetID and Period_From_new__c<=:pFrom and Period_To__c >=:pTo
order by createdDate Asc];
for(integer i=0;i<rscBillRate.size();i++)
{
system.debug('++++++rscBillRate+++++++'+rscBillRate);
if(rscBillRate[i].Project_ID__r.Billing_Rate__c == 'Monthly')
{
system.debug('++++++rscBillRate 9+++++++'+rscBillRate[i].Project_ID__r.Billing_Rate__c);
system.debug('++++++rscBillRate[i].Bill_Rate__c 11+++++++'+rscBillRate[i].Bill_Rate__c);
system.debug('++++++rscBillRate[i].Project_ID__r.Standard_Hours__c 12+++++++'+rscBillRate[i].Project_ID__r.Standard_Hours__c);
system.debug('++++++rscBillRate[i].Total_Billable_Hours__c 13+++++++'+rscBillRate[i].Total_Billable_Hours__c);
//StandardHours
//rscBillRate[i].Bill_Rate__c = (rscBillRate[i].Bill_Rate__c /rscBillRate[i].Project_ID__r.Standard_Hours__c)*rscBillRate[i].Total_Billable_Hours__c;
//rscBillRate[i].Bill_Rate__c = (rscBillRate[i].Bill_Rate__c /StandardHours)*rscBillRate[i].Total_Billable_Hours__c;
system.debug('++++++rscBillRate 3+++++++'+rscBillRate[i].Project_ID__r.Billing_Rate__c);
}
rscBillRate[i].Total_Billable_Hours__c = 0;
for(integer k=0;k<tCard.size();k++)
{
if(tCard[k].Date__c <= rscBillRate[i].Period_To__c && tCard[k].Date__c>=rscBillRate[i].Period_From_new__c)
{
rscBillRate[i].Total_Billable_Hours__c = rscBillRate[i].Total_Billable_Hours__c + tCard[k].Hours__c ;
}
}
system.debug('++++++rscBillRate 4+++++++'+rscBillRate[i]);
rscBillRate[i].Period_From_new__c = lstTC[0].Period_From__c;
rscBillRate[i].Period_To__c = lstTC[0].Period_To__c ;
}
system.debug('++++++rscBillRate 1+++++++'+rscBillRate);
if(bIsGenerated)
{
List<Invoice_Details__c> lstInvDtls = [Select id,Amount__c,From__c,Generate_Invoice__c,Hours__c,Rate__c,Rate_Type__c,Resource_Name__c,To_Date__c from Invoice_Details__c where Generate_Invoice__c =: parentId];
system.debug('++++++lstInvDtls+++++++'+lstInvDtls);
system.debug('++++++parentId+++++++'+parentId);
if(lstInvDtls.size()<=0)
{
//Save record in invoice detail
List<Invoice_Details__c> lstInsrtInvDtl = new List<Invoice_Details__c>();
for(integer i=0;i<rscBillRate.size();i++)
{
wrapperInvoiceDetails obj = new wrapperInvoiceDetails(rscBillRate[i]);
lstWrpInvDtl.add(obj);
Invoice_Details__c objInv = new Invoice_Details__c();
objInv.Generate_Invoice__c = parentId ;
objInv.Amount__c = obj.Amount;
objInv.Hours__c = obj.Hours;
objInv.Rate__c = obj.Rate;
objInv.Rate_Type__c = obj.RateType;
objInv.To_Date__c = obj.ToDate;
objInv.From__c = obj.FromDate;
objInv.Resource_Name__c = obj.ResourceName ;
lstInsrtInvDtl.add(objInv);
}
system.debug('++++++lstInsrtInvDtl+++++++'+lstInsrtInvDtl);
insert lstInsrtInvDtl;
}
else
{
//get data from invoice details
for(integer i=0;i<lstInvDtls.size();i++)
{
wrapperInvoiceDetails obj = new wrapperInvoiceDetails(lstInvDtls[i]);
lstWrpInvDtl.add(obj);
}
}
}
else
{
for(integer i=0;i<rscBillRate.size();i++)
{
wrapperInvoiceDetails obj = new wrapperInvoiceDetails(rscBillRate[i]);
lstWrpInvDtl.add(obj);
}
system.debug('++++++sBillingRate+++++++'+sBillingRate);
if(sBillingRate == 'Monthly')
{
//lstWrpInvDtl[0].Amount = lstWrpInvDtl[0].Amount__c;
lstWrpInvDtl[0].Amount = (lstWrpInvDtl[0].Rate/StandardHours)* lstWrpInvDtl[0].Hours;
system.debug('++++++lstWrpInvDtl[0].Amount+++++++'+lstWrpInvDtl[0].Amount);
}
if(sBillingRate == 'Hourly')
{
lstWrpInvDtl[0].Amount = lstWrpInvDtl[0].Rate * lstWrpInvDtl[0].Hours ;
system.debug('++++++lstWrpInvDtl[0].Amount+++++++'+lstWrpInvDtl[0].Amount);
}
}
}
public class wrapperInvoiceDetails
{
public Id InvDtlId{get;set;}
public boolean isChecked{get;set;}
public Id ResourceId{get;set;}
public string ResourceName{get;set;}
public decimal Hours{get;set;}
public decimal Rate{get;set;}
public string RateType{get;set;}
public decimal Amount{get;set;}
public date ToDate{get;set;}
public date FromDate{get;set;}
public wrapperInvoiceDetails()
{}
public wrapperInvoiceDetails(Resource_Bill_Rate__c obj)
{
//ResourceId = obj.Resource__c;
ResourceName = obj.Resource__r.Name;
Hours = obj.Total_Billable_Hours__c;
Rate = obj.Bill_Rate__c;
RateType = obj.Bill_Type_New__c;
//Amount = obj.Bill_Rate__c * obj.Total_Billable_Hours__c;
Amount = 0;
ToDate = obj.Period_To__c ;
FromDate = obj.Period_From_new__c ;
}
public wrapperInvoiceDetails(Invoice_Details__c obj)
{
InvDtlId = obj.id;
//ResourceId = obj.Resource__c;
ResourceName = obj.Resource_Name__c;
Hours = obj.Hours__c;
Rate = obj.Rate__c;
RateType = obj.Rate_Type__c;
Amount = obj.Amount__c;
ToDate = obj.To_Date__c;
FromDate = obj.From__c;
}
public wrapperInvoiceDetails(Billing_Repository__c obj)
{
//ResourceId = obj.Resource__c;
system.debug('++++++obj 1+++++'+obj);
if(obj.Customer_Billing__r != null)
{
ResourceName = obj.Customer_Billing__r.Startsheet__r.Resource__r.Name;
system.debug('++++++obj 2+++++'+obj);
}
else
{
ResourceName ='';
system.debug('++++++obj 3+++++'+obj);
}
Hours = obj.Total_Billable_Hours__c ;
if(obj.Customer_Billing__r !=null)
{
system.debug('++++++obj 4+++++'+obj.Customer_Billing__r.Startsheet__r.Billing_Rate__c);
if(obj.Customer_Billing__r.Startsheet__r.Billing_Rate__c == 'Hourly')
Rate = obj.Agency_Rate_Hour__c;
else
Rate = obj.Agency_Rate_Month__c;
RateType = obj.Customer_Billing__r.Startsheet__r.Billing_Rate__c;
system.debug('++++++obj 5+++++'+obj.Agency_Rate_Hour__c);
}
else
{
Rate =0;
RateType ='';
system.debug('++++++obj 6+++++'+obj);
}
//Amount = obj.Bill_Rate__c * obj.Total_Billable_Hours__c;
//Amount = Rate
ToDate = obj.To_Date__c;
FromDate = obj.From_Date__c;
}
}
}
Test Class - For test class - please download the same. When I pasted the class it blocked me due to space issues. Please download the class from below link.
https://www.dropbox.com/s/odol33468mx7hbw/ResourceTestBill.txt
Trigger For Trg_CalculateHours
trigger trg_CalculateHours on Resource_Bill_Rate__c (before update)
{
Public Decimal TotalBillableHours = 0;
public ID ProjectID;
public integer i=0;
public Date pFrom;
public Date pTo;
Set<Id> rscBillrt = new Set<Id>();
List<Resource_Bill_Rate__c> lstRsc = new List<Resource_Bill_Rate__c>();
List<Timecard_Entries__c> tCard = new List<Timecard_Entries__c>();
List<Timecard_Entries__c> tCard2 = new List<Timecard_Entries__c>();
for(Resource_Bill_Rate__c rs : trigger.new)
{
if(rs.Trigger_to_Calculate_Hours__c==TRUE)
rscBillrt.add(rs.Id);
}
lstRsc = [Select Period_From_new__c,Period_To__c,Project_ID__c from Resource_Bill_Rate__c where Id in:rscBillrt];
system.debug('*********************lstRsc : '+lstRsc);
for(Resource_Bill_Rate__c r: lstRsc)
{
ProjectID = r.Project_ID__c;
pFrom = r.Period_From_new__c;
pTo = r.Period_To__c;
}
system.debug('*********************ProjectID : '+ProjectID);
system.debug('*********************pFrom : '+pFrom);
system.debug('*********************pTo : '+pTo);
tCard = [SELECT Hours__c,Project_ID__c, Invoice_Generated__c, TimeCard__c FROM Timecard_Entries__c WHERE Project_ID__c
=:ProjectID and Date__c >=:pFrom and Date__c <=:pTo];
tCard2 = [SELECT Hours__c,Project_ID__c, Invoice_Generated__c, TimeCard__c FROM Timecard_Entries__c ];
system.debug('*********************tCard : '+tCard.size());
system.debug('*********************tCard2 : '+tCard2.size());
system.debug('*********************tCard2 : '+tCard2);
for(Timecard_Entries__c t: tCard)
{
if(t.Invoice_Generated__c!=TRUE){
if(i<tCard.size())
{
TotalBillableHours += t.Hours__c;
i++;
system.debug('*********************Total Billable Hours : '+TotalBillableHours );
system.debug('*********************Startsheet(Project) Name : '+t.Project_ID__c);
}
}
}
for(Resource_Bill_Rate__c rsc:trigger.new)
{
rsc.Total_Billable_Hours__c = TotalBillableHours;
}
system.debug('*********************Total Billable Hours : '+TotalBillableHours);
}
@isTest(SeeAllData=true)
and in the org you are deploying to there are a large number of rows. Fixing the test is one thing, but you also need to make sure your trigger works (uses a selective enough query) with large numbers of rows. I suggest you post the trigger and test source code if you need more help.trg_CalculateHours
) to fail. So effectively your testResourceBillRate class is exposing a bug in that trigger code. Using@isTest(seeAllData = true)
is generally a bad idea so simply removing that from testResourceBillRate may make that test work. But there is still the serious problem intrg_CalculateHours
that needs addressing of its query failing with large volumes of data. See @crmprogdev's suggestions about the other test failures too.