You need to sign in to do that
Don't have an account?
chiranjib rout
test class for this trigger
hii friends please suggest me test class for this below. i have also written one test class but showing error
trigger subtotal on Revenue__c (after insert, before update) {
List<Revenue__c> revlist = new List<Revenue__c>(); //initialize list
Set<String> eCodeSet = new Set<String>();
for(Revenue__c rev:Trigger.new)
{
if(rev.ECode__c!=null){
eCodeSet.add(rev.ECode__c);
}
}
//get all the SCSCHAMPS__Appointment__c records
Map<String,SCSCHAMPS__Appointment__c> appMap = new Map<String,SCSCHAMPS__Appointment__c>();
Map<String,Invoice__c> invoiceMap = new Map<String,Invoice__c>();
Map<String,Invoice_Line_Item__c> invoiceLineItemMap = new Map<String,Invoice_Line_Item__c>();
for(SCSCHAMPS__Appointment__c appointment : [select AvvasECode__c,Name_of_the_Candidate__c,Client_Name__c,Date_of_Onboarding__c,
Last_Working_Date__c,Location__c from SCSCHAMPS__Appointment__c where AvvasECode__c in : eCodeSet])
{
appMap.put(appointment.AvvasECode__c,appointment);
}
//get all invoice records
for(Invoice__c invoice : [select id,Name,Emp_Code__c,Invoice_Category__c,createddate,
Sub_Total__c from Invoice__c where Emp_Code__c in : eCodeSet])
{
invoiceMap.put(invoice.Emp_Code__c,invoice);
System.debug('++++invoice'+invoiceMap);
}
//get all invoice lineitem records
for(Invoice_Line_Item__c lineItem : [Select id,Name,Employee_Code__c,Total__c
from Invoice_Line_Item__c where Employee_Code__c =: eCodeSet])
{
invoiceLineItemMap.put(lineItem.Employee_Code__c,lineItem);
}
for(Revenue__c rev:Trigger.new)
{
if(rev.ECode__c!=null && appMap.containsKey(rev.ECode__c))
{
rev.Talent_Name__c= appMap.get(rev.ECode__c).Name_of_the_Candidate__c;
rev.DOJ__c= appMap.get(rev.ECode__c).Date_of_Onboarding__c;
rev.Client_Name__c = appMap.get(rev.ECode__c).Client_Name__c;
rev.Location__c= appMap.get(rev.ECode__c).Location__c;
rev.Last_Working_Date__c=appMap.get(rev.ECode__c).Last_Working_Date__c;
}
if(rev.ECode__c!=null && rev.InvoiceCategory__c=='individual' && invoiceMap.containsKey(rev.ECode__c))
{
rev.Revenue_Without_ST__c=invoiceMap.get(rev.ECode__c).Sub_Total__c;
}
else if(rev.ECode__c!=null && rev.InvoiceCategory__c=='consolidated'&& invoiceLineItemMap.containsKey(rev.ECode__c))
{
rev.Revenue_Without_ST__c=invoiceLineItemMap.get(rev.ECode__c).Total__c;
}
}
}
Here is my test class but showing error and not executing properly
@isTest
public class testRevenue {
static testMethod void testMethod1() {
InvoiceCategory__c InvC = newInvoiceCategory__c(name = 'Test1');
insert InvC;
Invoice_Type__c InvT = new Invoice_Type__c(name = 'Test2');
insert InvT;
Salary_Type__c SalT = new ISalary_Type__c(name = 'Test2');
insert SalT
Test.StartTest();
Revenue__c rev= new Revenue__c();
rev.ECode__c='Test0';
InvoiceCategory__c invC = new InvoiceCategory__c
List<SelectOption> listInvCt = rev.InvoiceCategory__c();
List<SelectOption> listInvTy = rev.Invoice_Type__c();
List<SelectOption> listSalTy = rev.Salary_Type__c();
rev.SelInvoiceCategory__c ='Test1';
rev.SelInvoice_Type__c ='Test2';
rev.SelSalary_Type__c ='Test3';
rev.Salary_Processed_Month__c=system.today();
Test.StopTest();
}
}
trigger subtotal on Revenue__c (after insert, before update) {
List<Revenue__c> revlist = new List<Revenue__c>(); //initialize list
Set<String> eCodeSet = new Set<String>();
for(Revenue__c rev:Trigger.new)
{
if(rev.ECode__c!=null){
eCodeSet.add(rev.ECode__c);
}
}
//get all the SCSCHAMPS__Appointment__c records
Map<String,SCSCHAMPS__Appointment__c> appMap = new Map<String,SCSCHAMPS__Appointment__c>();
Map<String,Invoice__c> invoiceMap = new Map<String,Invoice__c>();
Map<String,Invoice_Line_Item__c> invoiceLineItemMap = new Map<String,Invoice_Line_Item__c>();
for(SCSCHAMPS__Appointment__c appointment : [select AvvasECode__c,Name_of_the_Candidate__c,Client_Name__c,Date_of_Onboarding__c,
Last_Working_Date__c,Location__c from SCSCHAMPS__Appointment__c where AvvasECode__c in : eCodeSet])
{
appMap.put(appointment.AvvasECode__c,appointment);
}
//get all invoice records
for(Invoice__c invoice : [select id,Name,Emp_Code__c,Invoice_Category__c,createddate,
Sub_Total__c from Invoice__c where Emp_Code__c in : eCodeSet])
{
invoiceMap.put(invoice.Emp_Code__c,invoice);
System.debug('++++invoice'+invoiceMap);
}
//get all invoice lineitem records
for(Invoice_Line_Item__c lineItem : [Select id,Name,Employee_Code__c,Total__c
from Invoice_Line_Item__c where Employee_Code__c =: eCodeSet])
{
invoiceLineItemMap.put(lineItem.Employee_Code__c,lineItem);
}
for(Revenue__c rev:Trigger.new)
{
if(rev.ECode__c!=null && appMap.containsKey(rev.ECode__c))
{
rev.Talent_Name__c= appMap.get(rev.ECode__c).Name_of_the_Candidate__c;
rev.DOJ__c= appMap.get(rev.ECode__c).Date_of_Onboarding__c;
rev.Client_Name__c = appMap.get(rev.ECode__c).Client_Name__c;
rev.Location__c= appMap.get(rev.ECode__c).Location__c;
rev.Last_Working_Date__c=appMap.get(rev.ECode__c).Last_Working_Date__c;
}
if(rev.ECode__c!=null && rev.InvoiceCategory__c=='individual' && invoiceMap.containsKey(rev.ECode__c))
{
rev.Revenue_Without_ST__c=invoiceMap.get(rev.ECode__c).Sub_Total__c;
}
else if(rev.ECode__c!=null && rev.InvoiceCategory__c=='consolidated'&& invoiceLineItemMap.containsKey(rev.ECode__c))
{
rev.Revenue_Without_ST__c=invoiceLineItemMap.get(rev.ECode__c).Total__c;
}
}
}
Here is my test class but showing error and not executing properly
@isTest
public class testRevenue {
static testMethod void testMethod1() {
InvoiceCategory__c InvC = newInvoiceCategory__c(name = 'Test1');
insert InvC;
Invoice_Type__c InvT = new Invoice_Type__c(name = 'Test2');
insert InvT;
Salary_Type__c SalT = new ISalary_Type__c(name = 'Test2');
insert SalT
Test.StartTest();
Revenue__c rev= new Revenue__c();
rev.ECode__c='Test0';
InvoiceCategory__c invC = new InvoiceCategory__c
List<SelectOption> listInvCt = rev.InvoiceCategory__c();
List<SelectOption> listInvTy = rev.Invoice_Type__c();
List<SelectOption> listSalTy = rev.Salary_Type__c();
rev.SelInvoiceCategory__c ='Test1';
rev.SelInvoice_Type__c ='Test2';
rev.SelSalary_Type__c ='Test3';
rev.Salary_Processed_Month__c=system.today();
Test.StopTest();
}
}
add line;