You need to sign in to do that
Don't have an account?
Code Coverage for Apex Class?
I wrote the following class to call from my triggers and ensure they don't run recursively. This is the code:
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if(run){
run=false;
return true;
}else{
return run;
}
}
}
Do I need to write a test class for this class in order to push it to our instance? If so, can someone point me in the right direction? Thanks.
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if(run){
run=false;
return true;
}else{
return run;
}
}
}
Do I need to write a test class for this class in order to push it to our instance? If so, can someone point me in the right direction? Thanks.
@isTest (seeAllData=true)
private class testEditSchedule{
static testMethod void testUpdateSchedule() {
List<Account> aList = new List<Account>();
Account a = new Account(
Name = 'Test Account'
);
aList.add(a);
insert aList;
List<Opportunity> oList = new List<Opportunity>();
Opportunity o = new Opportunity(
Name = 'Test Opportunity',
StageName = 'Discovery',
CloseDate = Date.today(),
Contract_Start_Date__c = Date.today(),
AccountId = a.Id
);
oList.add(o);
insert oList;
//Create Product
Product2 prod = new Product2();
prod.IsActive = true;
prod.Name = 'Onboarding';
prod.CanUseRevenueSchedule=true;
insert prod;
//Create PriceBook
Pricebook2 pb = new Pricebook2();
pb.Name = 'Test';
pb.IsActive = true;
insert pb;
List<Pricebook2> PbList = [Select Id, Name, IsActive From Pricebook2 where IsStandard = true LIMIT 1];
//Pricebook2 standardpb = [Select Id, Name, IsActive From Pricebook2 where IsStandard = true LIMIT 1];
PricebookEntry standardpbe = new PricebookEntry();
standardpbe.Pricebook2Id = PbList[0].Id;
standardpbe.Product2Id = prod.Id;
standardpbe.UnitPrice = 10000;
standardpbe.IsActive = true;
standardpbe.UseStandardPrice = false;
insert standardpbe;
PricebookEntry pbe = new PricebookEntry();
pbe.Pricebook2Id = pb.Id;
pbe.Product2Id = prod.Id;
pbe.UnitPrice = 10000;
pbe.IsActive = true;
pbe.UseStandardPrice = false;
insert pbe;
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
List<OpportunityLineItem> oliAnnuallyList = new List<OpportunityLineItem>();
List<OpportunityLineItem> oliQuarterlyList = new List<OpportunityLineItem>();
List<OpportunityLineItem> oliMonthlyList = new List<OpportunityLineItem>();
OpportunityLineItem oliAnnually = new OpportunityLineItem(
OpportunityId = o.Id,
PricebookEntryId = pbe.id,
TotalPrice = 1,
Quantity=2,
Payment_Terms__c ='Annually',
Duration__c = 12
);
OpportunityLineItem oliMonthly= new OpportunityLineItem(
OpportunityId = o.Id,
PricebookEntryId = pbe.id,
TotalPrice = 1,
Quantity=2,
Payment_Terms__c ='Monthly',
Duration__c = 1
);
OpportunityLineItem oliQuarterly= new OpportunityLineItem(
OpportunityId = o.Id,
PricebookEntryId = pbe.id,
TotalPrice = 1,
Quantity=2,
Payment_Terms__c ='Quarterly',
Duration__c = 3
);
OpportunityLineItem oli= new OpportunityLineItem(
OpportunityId = o.Id,
PricebookEntryId = pbe.id,
TotalPrice = 1,
Quantity=2,
Payment_Terms__c = 'Up Front',
Duration__c = 12
);
oliAnnuallyList.add(oliAnnually);
oliMonthlyList.add(oliMonthly);
oliQuarterlyList.add(oliQuarterly);
oliList.add(oli);
insert oliList;
insert oliAnnuallyList;
insert oliQuarterlyList;
insert oliMonthlyList;
//Your trigger should have OpportunityLineItemSchedule logic then following asert will pass else it will fail
List<OpportunityLineItem> lstOptyLi =[SELECT HasRevenueSchedule from OpportunityLineItem where Id =:oli.id];
System.assertEquals(True, lstOptyLi[0].HasRevenueSchedule);
List<OpportunityLineItem> lstOptyLi_2 =[SELECT HasRevenueSchedule from OpportunityLineItem where Id =:oliAnnually.id];
System.assertEquals(True, lstOptyLi_2[0].HasRevenueSchedule);
List<OpportunityLineItem> lstOptyLi_3 =[SELECT HasRevenueSchedule from OpportunityLineItem where Id =:oliQuarterly.id];
System.assertEquals(True, lstOptyLi_3[0].HasRevenueSchedule);
List<OpportunityLineItem> lstOptyLi_4 =[SELECT HasRevenueSchedule from OpportunityLineItem where Id =:oliMonthly.id];
System.assertEquals(True, lstOptyLi_4[0].HasRevenueSchedule);
}
}