You need to sign in to do that
Don't have an account?

test class only covers 50% of the trigger
Hello ,
I have a trigger fro defaulting the standard pricebook for the order
My test class is
The problem is when I run the test the test class passes but covers only 50% of the trigger.
Any ideas why??
I have a trigger fro defaulting the standard pricebook for the order
trigger InsertPriceBookTrigger on Order (before insert) { List<Pricebook2> stdPBL = [select id from Pricebook2 where IsStandard = TRUE]; if(!stdPBL.isEmpty()){ for(Order o: Trigger.new) o.PriceBook2Id = stdPBL[0].id; } }
My test class is
@isTest public class Test5{ public static testmethod void InsertPriceBookTrigger_Test1() { Account a = new Account( Name = 'Test' ); insert a; Order o = new Order(name='Test1',AccountId=a.id,EffectiveDate=system.today(),status='draft'); insert o; List<Pricebook2> stdPBL = [select id from Pricebook2 where IsStandard = TRUE]; if (!stdPBL.isEmpty()) { system.assertequals(stdPBL[0].id,o.PriceBook2Id); } } }
The problem is when I run the test the test class passes but covers only 50% of the trigger.
Any ideas why??
That PriceBook should be available in test class. So use seeAllDate = true
Try below test class
Regards,
Bhanu Mahesh
All Answers
That PriceBook should be available in test class. So use seeAllDate = true
Try below test class
Regards,
Bhanu Mahesh
That covered the code up to 100%