+ Start a Discussion
syricsyric 

Help with Trigger test failing - error System.NullPointerException

I have a trigger I wrote that works great when I test it in the UI, but my test is failing.  I get the following error:
Error Message	System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, triggerTest: execution of BeforeInsert

caused by: System.NullPointerException: Argument cannot be null.

Trigger.triggerTest: line 294, column 1: []
Stack Trace	Class.testtest.myUnitTest: line 61, column 1
If I'm understanding this correctly it says its failing when it tries to insert the opportunitylineitem because when the trigger tries to do "a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);" and it thinks No_Ordered__c or ListPrice is NULL.  I get this error whether or not I use a the test product or a real product already in the system that I know works fine when I test in the UI.  Please tell me what I am doing wrong.  Any help is appreciated.  Here is the code for the trigger and the test.  I trimmed down the test to test only one product.

TRIGGER
trigger triggerTest on OpportunityLineItem (before insert, before update) {

		decimal disc;
		decimal sub;
		decimal servamt;
		decimal billcalc;
		Integer quartercalc;
		Integer enddate;

		for(OpportunityLineItem a : Trigger.New){
			a.Quantity = (a.No_Ordered__c * a.Service_Duration__c);
			sub = (a.Quantity * a.UnitPrice);
			if(a.Discount != NULL){
				disc = (a.Discount * .01);
				a.TotalPrice = (sub - (sub * disc));
			}else{
				a.TotalPrice = sub;	
			}
			servamt = (a.Quantity / a.No_Ordered__c);
			a.Service_Amount__c = (a.TotalPrice / servamt);
			if(a.PB__c == 'Weekly'){
				if(a.Billing_Period__c == 'Weekly'){
					billcalc = 1;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 7);
					a.End_Date__c = a.ServiceDate.addDays(enddate);
				}else if(a.Billing_Period__c == 'Quarterly'){
					billcalc = 13;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 7);
					a.End_Date__c = a.ServiceDate.addDays(enddate);				
				}else if(a.Billing_Period__c == 'Semi-Annual'){
					billcalc = 26;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 7);
					a.End_Date__c = a.ServiceDate.addDays(enddate);				
				}else if(a.Billing_Period__c == 'Annual'){
					billcalc = 52;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);				
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 7);
					a.End_Date__c = a.ServiceDate.addDays(enddate);							
				}

			}else if(a.PB__c == 'Monthly' || a.PB__c == 'Monthly D'){
				if(a.Billing_Period__c == 'Monthly'){
					billcalc = 1;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}else if(a.Billing_Period__c == 'Every Other Month'){
					billcalc = 2;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}else if(a.Billing_Period__c == 'Quarterly'){
					billcalc = 3;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}else if(a.Billing_Period__c == 'Semi-Annual'){
					billcalc = 6;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}else if(a.Billing_Period__c == 'Annual'){
					billcalc = 12;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}

			}else if(a.PB__c == 'Quarterly'){
				if(a.Billing_Period__c == 'Quarterly'){
					billcalc = 1;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 3);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}else if(a.Billing_Period__c == 'Semi-Annual'){
					billcalc = 2;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 3);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}else if(a.Billing_Period__c == 'Annual'){
					billcalc = 4;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 3);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}else if(a.Billing_Period__c == 'Monthly'){
					billcalc = 3;
					a.Billing_Amount__c = (a.Service_Amount__c / billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice / billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c / billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 3);
					a.End_Date__c = a.ServiceDate.addMonths(enddate);
				}

			}else if(a.PB__c == 'Annual'){
				if(a.Billing_Period__c == 'Annual'){
					billcalc = 1;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addYears(enddate);
				}else if(a.Billing_Period__c == 'Monthly'){
					billcalc = 12;
					a.Billing_Amount__c = (a.Service_Amount__c / billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice / billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c / billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addYears(enddate);
				}else if(a.Billing_Period__c == 'Every Other Month'){
					billcalc = 6;
					a.Billing_Amount__c = (a.Service_Amount__c / billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice / billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c / billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addYears(enddate);
				}else if(a.Billing_Period__c == 'Quarterly'){
					billcalc = 4;
					a.Billing_Amount__c = (a.Service_Amount__c / billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice / billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c / billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addYears(enddate);
				}else if(a.Billing_Period__c == 'Semi-Annual'){
					billcalc = 2;
					a.Billing_Amount__c = (a.Service_Amount__c / billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice / billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c / billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addYears(enddate);
				}

			}else if(a.PB__c == 'One Time' || a.PB__c == 'One Time D'){
				if(a.Billing_Period__c == 'Monthly'){
					billcalc = 1;
					a.Billing_Amount__c = (a.Service_Amount__c * billcalc);
					a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
					a.List_Price_Bill__c = (a.ListPrice * billcalc);
					a.List_Price_Extd__c = (a.List_Price_Svc__c * billcalc);
					a.Billing_Savings__c = (a.Billing_Amount__c - a.List_Price_Extd__c);
					if(a.Billing_Savings__c >= 0){
						a.Billing_Savings__c = NULL;
					}
					a.Per_Item_Bill__c = (a.Billing_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Bill__c = (a.List_Price_Bill__c - a.Per_Item_Bill__c);
					a.Service_Savings__c = (a.Service_Amount__c - a.List_Price_Svc__c);
					if(a.Service_Savings__c >= 0){
						a.Service_Savings__c = NULL;
					}
					a.Per_Item_Svc__c = (a.Service_Amount__c / a.No_Ordered__c);
					a.Discount_Amount_Svc__c = (a.ListPrice - a.Per_Item_Svc__c);
					enddate = (a.Service_Duration__c.intValue() * 1);
					a.End_Date__c = a.ServiceDate.addDays(enddate);
				}

			}

		}


	}

TEST CLASS
 
/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest(SeeAllData=true)
private class testtest {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test

        Date now = date.today();
        integer day = now.day();
        
        // CREATE ACCOUNT
        Account newAccount = new Account(Name = 'Test Account', Phone='817-999-9999' );
        insert newAccount;

         // CREATE CONTACT
        Contact newContact = new Contact(LastName = 'Test Contact', AccountId = newAccount.Id );
        insert newContact; 

        // CREATE OPPORTUNITY
        Opportunity newOpp = new Opportunity(Name = 'Test Opportunity', CloseDate = System.today(), AccountId = newAccount.Id, Contact_Name__c = newContact.Id, StageName = 'Initial Interview' );
        insert newOpp;
        
        // GET STANDARD PRICEBOOK
		Pricebook2  standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1];

		// CREATE CUSTOM PRICEBOOK
		Pricebook2 pbk1 = new Pricebook2 (Name='Test Pricebook Entry 1',Description='Test Pricebook Entry 1', isActive=true);
		insert pbk1;

		// CREATE PRODUCT
		Product2 prd1 = new Product2 (Name='Test Product Entry 1',Description='Test Product Entry 1',productCode = 'ABC', isActive = true, Pricing_Basis__c = 'Annual' );
		insert prd1;

		// CREATE PRICEBOOKENTRY
		PricebookEntry pbe1 = new PricebookEntry (Product2ID=prd1.id,Pricebook2ID=standardPb.id,UnitPrice=50, isActive=true);
		insert pbe1;


        // CREATE OPPORTUNITYPRODUCTS
        OpportunityLineItem newProdAnnual = new OpportunityLineItem (Billing_Period__c = 'Annual', OpportunityId = newOpp.Id, Service_Duration__c = 1, ServiceDate = now, End_Date__c = now, PricebookEntryId = pbe1.Id, No_Ordered__c = 1, UnitPrice = 50, Quantity = 1);       
        insert newProdAnnual;

        //QUERY
        OpportunityLineItem a =[SELECT ID, Quantity, TotalPrice, Discount, UnitPrice, Billing_Amount__c, List_Price_Svc__c, List_Price_Bill__c, List_Price_Extd__c, Billing_Savings__c, Per_Item_Bill__c, Discount_Amount_Bill__c, Service_Savings__c, Per_Item_Svc__c, Discount_Amount_Svc__c, End_Date__c, ServiceDate from OpportunityLineItem WHERE ID =: newProdAnnual.Id ];


        //VALIDATE DATA WAS UPDATED CORRECTLY

		//Annual
		System.assertEquals(a.Quantity, 1);
		System.assertEquals(a.TotalPrice, 50.00);
		System.assertEquals(a.Discount, 0);
		System.assertEquals(a.Billing_Amount__c, 50.00);
		System.assertEquals(a.List_Price_Svc__c, 50.00);
		System.assertEquals(a.List_Price_Bill__c, 50.00);
		System.assertEquals(a.List_Price_Extd__c, 50.00);
		System.assertEquals(a.Billing_Savings__c, NULL);
		System.assertEquals(a.Per_Item_Bill__c, 50.00);		
		System.assertEquals(a.Discount_Amount_Bill__c, 0.00);
		System.assertEquals(a.Service_Savings__c, NULL);
		System.assertEquals(a.Per_Item_Svc__c, 50.00);
		System.assertEquals(a.Discount_Amount_Svc__c, 0.00);
		System.assertEquals(a.End_Date__c, a.ServiceDate.addYears(1));

    }
}



 
ShotShot
What about to add before this line:
 a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
this:
System.debug(a.No_Ordered__c);
System.debug(a.ListPrice);

And show us a log file!?
ShotShot
Or just add this:
if (a.No_Ordered__c != null && a.ListPrice != null){
     a.List_Price_Svc__c = (a.No_Ordered__c * a.ListPrice);
}

 
syricsyric
I put in the debug statements.  I will post the the log below   I understand what you are saying by the If statements, but my question is why is  ListPrice = NULL in the debug?  ListPrice is a default required field that is derrived from what I set in PricebookEntry. It is not something can be edited.  --Thanks

DEBUG - (The log was too big to post all of so I posted the last chunk that pertained to the Opportunity.)

17:13:32.699|CUMULATIVE_LIMIT_USAGE_END

17:13:34.595 (3595945966)|CODE_UNIT_FINISHED|ProrateTrigger on Opportunity trigger event AfterInsert for [006g0000006Th5n]
17:13:34.599 (3599727170)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Opportunity
17:13:34.628 (3628608315)|WF_RULE_EVAL_BEGIN|Workflow
17:13:34.628 (3628641351)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Banner Notification-DMM BT BC|01Q60000000dHwN|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.682 (3682177187)|WF_RULE_FILTER|[Opportunity : # of Banners not equal to 0.0] AND
 [Opportunity : Opportunity Record Type equals DMM Boat Trader boats.com, DMM MMS, DX1 Marine] AND
 [Opportunity : Stage equals Approved For Setup, Closed Won]
17:13:34.682 (3682227921)|WF_RULE_EVAL_VALUE|0
17:13:34.682 (3682234333)|WF_CRITERIA_END|false
17:13:34.682 (3682253214)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Banner Notification-DMM YW|01Q60000000dHwO|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.682 (3682318385)|WF_RULE_FILTER|[Opportunity : # of Banners not equal to 0.0] AND
 [Opportunity : Opportunity Record Type equals DMM BCG, DMM YachtWorld] AND
 [Opportunity : Stage equals Approved For Setup, Closed Won, Signed and Submitted for Approval]
17:13:34.682 (3682337017)|WF_RULE_EVAL_VALUE|0
17:13:34.682 (3682340316)|WF_CRITERIA_END|false
17:13:34.682 (3682351840)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Oppty-Add Data Source|01Q60000000V5MQ|ON_ALL_CHANGES|0
17:13:34.682 (3682452541)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]TRUE|Values:
17:13:34.682 (3682457188)|WF_CRITERIA_END|true
17:13:34.715 (3715736560)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|DPM Boston Publisher Email|01Q60000000V4eU|ON_ALL_CHANGES|0
17:13:34.715 (3715778691)|WF_RULE_FILTER|[Account : Data Source equals DPM BO]
17:13:34.715 (3715795960)|WF_RULE_EVAL_VALUE|
17:13:34.715 (3715799472)|WF_CRITERIA_END|false
17:13:34.715 (3715810709)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Marine DX1 Contract Out|01Q60000000dK7w|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.715 (3715851135)|WF_RULE_FILTER|[Opportunity : Stage equals Contract Out]
AND [Opportunity : Opportunity Record Type equals DX1 Marine]
17:13:34.715 (3715881842)|WF_RULE_EVAL_VALUE|Initial Interview
17:13:34.715 (3715885766)|WF_CRITERIA_END|false
17:13:34.715 (3715897528)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Send New TLP Contract Email|01Q60000000Mev4|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.715 (3715928686)|WF_RULE_FILTER|[Opportunity : Stage equals Signed and Submitted for Approval, Signed]
AND [Opportunity : Opportunity Record Type equals TLP Record Type]
17:13:34.715 (3715948898)|WF_RULE_EVAL_VALUE|Initial Interview
17:13:34.715 (3715952226)|WF_CRITERIA_END|false
17:13:34.715 (3715962804)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|OM Approved for Set Up|01Q60000000dHFL|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.715 (3715991872)|WF_RULE_FILTER|[Opportunity : Stage equals Approved For Setup]
AND [Opportunity : Opportunity Record Type equals DMM Boat Trader boats.com]
17:13:34.716 (3716009678)|WF_RULE_EVAL_VALUE|Initial Interview
17:13:34.716 (3716013912)|WF_CRITERIA_END|false
17:13:34.716 (3716024391)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Marine DX1 Closed Won|01Q60000000dJdr|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.716 (3716052295)|WF_RULE_FILTER|[Opportunity : Stage equals Closed Won]
AND [Opportunity : Opportunity Record Type equals DX1 Marine]
17:13:34.716 (3716069296)|WF_RULE_EVAL_VALUE|Initial Interview
17:13:34.716 (3716072550)|WF_CRITERIA_END|false
17:13:34.716 (3716082460)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Agreement Ready - WS|01Q60000000V7ao|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.716 (3716109856)|WF_RULE_FILTER|[Opportunity : Opportunity Record Type equals CWS Record Type]
AND [Opportunity : Stage equals Agreement Ready]
17:13:34.716 (3716121847)|WF_RULE_EVAL_VALUE|01260000000UIZY
17:13:34.716 (3716124607)|WF_CRITERIA_END|false
17:13:34.716 (3716134193)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|DPM BA Publisher Email|01Q60000000V4eT|ON_ALL_CHANGES|0
17:13:34.716 (3716154286)|WF_RULE_FILTER|[Account : Data Source equals DPM BA]
17:13:34.716 (3716162139)|WF_RULE_EVAL_VALUE|
17:13:34.716 (3716164841)|WF_CRITERIA_END|false
17:13:34.716 (3716173705)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|DPM Change Layout Back to Unqualified|01Q60000000V3zu|ON_ALL_CHANGES|0
17:13:34.716 (3716669307)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]OR(ISPICKVAL({!ID:Account.00N600000029m5L}, "DPM BA" ), ISPICKVAL({!ID:Account.00N600000029m5L}, "DPM BO"))  && OR({!ID:00N60000002Zf0p}   >  {!ID:00N60000002Zf0o}, {!ID:00N60000002VZF2} > {!ID:00N60000002Zm12})|Values:Max_Core_Rollup__c=null, Account.Data_Source__c=null, Core_Product_Rollup__c=0, ProductsManager__Total_Line_Items__c=0, Has_Revenue_Schedule__c=0
17:13:34.716 (3716676373)|WF_CRITERIA_END|false
17:13:34.716 (3716689260)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|DPM Change Page Layout to allow Agreements|01Q60000000V3zv|ON_ALL_CHANGES|0
17:13:34.717 (3717095234)|WF_FORMULA|Formula:ENCODED:[treatNullAsNull]OR(ISPICKVAL({!ID:Account.00N600000029m5L}, "DPM BA" ), ISPICKVAL({!ID:Account.00N600000029m5L}, "DPM BO"))  && OR({!ID:00N60000002Zf0p}  <= {!ID:00N60000002Zf0o}, {!ID:00N60000002Zf0o} = 0.00) && OR( {!ID:00N60000002Zm12} =  {!ID:00N60000002VZF2} , {!ID:00N60000002VZF2}  = 0.00)|Values:Max_Core_Rollup__c=null, Account.Data_Source__c=null, Core_Product_Rollup__c=0, ProductsManager__Total_Line_Items__c=0, Has_Revenue_Schedule__c=0
17:13:34.717 (3717103495)|WF_CRITERIA_END|false
17:13:34.717 (3717116478)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|New Opportunity Created|01Q60000000MqyA|ON_CREATE_ONLY|0
17:13:34.717 (3717197243)|WF_RULE_FILTER|[Opportunity : Opportunity Owner Manager Email equals nicole.schantz@dominionenterprises.com] OR
 [Opportunity : Opportunity Owner Manager Email equals audra.macon@dominionenterprises.com] OR
 [Opportunity : Opportunity Owner Manager Email equals jimmy.wise@cycletrader.com] OR
 [Opportunity : Opportunity Owner Manager Email equals lynda.thomas@dominionenterprises.com]
17:13:34.717 (3717226475)|WF_RULE_EVAL_VALUE|bridgett.cherry@dominionenterprises.com
17:13:34.717 (3717232005)|WF_RULE_EVAL_VALUE|bridgett.cherry@dominionenterprises.com
17:13:34.717 (3717236205)|WF_RULE_EVAL_VALUE|bridgett.cherry@dominionenterprises.com
17:13:34.717 (3717240192)|WF_RULE_EVAL_VALUE|bridgett.cherry@dominionenterprises.com
17:13:34.717 (3717243248)|WF_CRITERIA_END|false
17:13:34.717 (3717254721)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|New Dealer Set ups|01Q60000000Mgoj|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.717 (3717287363)|WF_RULE_FILTER|[Opportunity : Dealer Set Up Start equals true]
17:13:34.717 (3717295800)|WF_RULE_EVAL_VALUE|0
17:13:34.717 (3717298507)|WF_CRITERIA_END|false
17:13:34.717 (3717307571)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|AX Opportunity Sync Failure|01Q60000000Mok3|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.717 (3717350580)|WF_RULE_FILTER|[Opportunity : AX Sync Error equals true] OR
 [Opportunity : AX Sync Error Reason not equal to null]
17:13:34.717 (3717365225)|WF_RULE_EVAL_VALUE|0
17:13:34.717 (3717370089)|WF_RULE_EVAL_VALUE|
17:13:34.717 (3717374001)|WF_CRITERIA_END|false
17:13:34.717 (3717384423)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Send New CWS Summary Form Completed|01Q60000000MkpH|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.717 (3717430511)|WF_RULE_FILTER|[Opportunity : Summary Form Completed equals true] AND
 [Opportunity : Opportunity Record Type equals CWS Record Type]
17:13:34.717 (3717446147)|WF_RULE_EVAL_VALUE|0
17:13:34.717 (3717449281)|WF_CRITERIA_END|false
17:13:34.717 (3717459590)|WF_CRITERIA_BEGIN|[Opportunity: Test Opportunity 006g0000006Th5n]|Marine DX1 Submitted for Approval|01Q60000000dK81|ON_CREATE_OR_TRIGGERING_UPDATE|0
17:13:34.717 (3717494881)|WF_RULE_FILTER|[Opportunity : Stage equals Signed and Submitted for Approval]
AND [Opportunity : Opportunity Record Type equals DX1 Marine]
17:13:34.717 (3717515505)|WF_RULE_EVAL_VALUE|Initial Interview
17:13:34.717 (3717519284)|WF_CRITERIA_END|false
17:13:34.717 (3717541149)|WF_SPOOL_ACTION_BEGIN|Workflow
17:13:34.717 (3717780683)|WF_ACTION| Field Update: 1;
17:13:34.717 (3717785925)|WF_RULE_EVAL_END
17:13:34.717 (3717846673)|WF_ACTIONS_END| Field Update: 1;
17:13:34.717 (3717852702)|CODE_UNIT_FINISHED|Workflow:Opportunity
17:13:34.731 (3731494502)|DML_END|[20]
17:13:34.731 (3731871139)|SOQL_EXECUTE_BEGIN|[23]|Aggregations:0|SELECT id, name, isActive FROM Pricebook2 WHERE IsStandard = TRUE LIMIT 1
17:13:34.735 (3735499012)|SOQL_EXECUTE_END|[23]|Rows:1
17:13:34.735 (3735852675)|DML_BEGIN|[27]|Op:Insert|Type:Pricebook2|Rows:1
17:13:34.955 (3955845779)|DML_END|[27]
17:13:34.956 (3956099514)|DML_BEGIN|[31]|Op:Insert|Type:Product2|Rows:1
17:13:35.015 (4015484255)|DML_END|[31]
17:13:35.015 (4015916602)|DML_BEGIN|[35]|Op:Insert|Type:PricebookEntry|Rows:1
17:13:35.066 (4066518967)|DML_END|[35]
17:13:35.066 (4066733375)|DML_BEGIN|[39]|Op:Insert|Type:PricebookEntry|Rows:1
17:13:35.083 (4083180706)|DML_END|[39]
17:13:35.083 (4083497615)|DML_BEGIN|[44]|Op:Insert|Type:OpportunityLineItem|Rows:1
17:13:35.134 (4134304337)|CODE_UNIT_STARTED|[EXTERNAL]|01qg00000000NP5|triggerTest on OpportunityLineItem trigger event BeforeInsert for [new]
17:13:35.134 (4134598248)|SYSTEM_METHOD_ENTRY|[10]|List<OpportunityLineItem>.iterator()
17:13:35.134 (4134629939)|SYSTEM_METHOD_EXIT|[10]|List<OpportunityLineItem>.iterator()
17:13:35.134 (4134643385)|SYSTEM_METHOD_ENTRY|[10]|system.ListIterator.hasNext()
17:13:35.134 (4134662236)|SYSTEM_METHOD_EXIT|[10]|system.ListIterator.hasNext()
17:13:35.134 (4134763957)|SYSTEM_METHOD_ENTRY|[11]|Decimal.multiply(Decimal)
17:13:35.134 (4134829482)|SYSTEM_METHOD_EXIT|[11]|Decimal.multiply(Decimal)
17:13:35.134 (4134913082)|SYSTEM_METHOD_ENTRY|[12]|Decimal.multiply(Decimal)
17:13:35.134 (4134947176)|SYSTEM_METHOD_EXIT|[12]|Decimal.multiply(Decimal)
17:13:35.135 (4135022679)|SYSTEM_METHOD_ENTRY|[19]|Decimal.divide(Decimal)
17:13:35.135 (4135097125)|SYSTEM_METHOD_EXIT|[19]|Decimal.divide(Decimal)
17:13:35.135 (4135137805)|SYSTEM_METHOD_ENTRY|[20]|Decimal.divide(Decimal)
17:13:35.135 (4135191570)|SYSTEM_METHOD_EXIT|[20]|Decimal.divide(Decimal)
17:13:35.135 (4135756899)|SYSTEM_METHOD_ENTRY|[293]|Decimal.multiply(Decimal)
17:13:35.135 (4135789460)|SYSTEM_METHOD_EXIT|[293]|Decimal.multiply(Decimal)
17:13:35.135 (4135847392)|SYSTEM_METHOD_ENTRY|[294]|System.debug(ANY)
17:13:35.135 (4135867844)|USER_DEBUG|[294]|DEBUG|1
17:13:35.135 (4135873899)|SYSTEM_METHOD_EXIT|[294]|System.debug(ANY)
17:13:35.135 (4135894291)|SYSTEM_METHOD_ENTRY|[295]|System.debug(ANY)
17:13:35.135 (4135904604)|USER_DEBUG|[295]|DEBUG|null
17:13:35.135 (4135909332)|SYSTEM_METHOD_EXIT|[295]|System.debug(ANY)
17:13:35.135 (4135937734)|SYSTEM_METHOD_ENTRY|[296]|Decimal.multiply(Decimal)
17:13:35.136 (4136050723)|SYSTEM_METHOD_EXIT|[296]|Decimal.multiply(Decimal)
17:13:35.136 (4136104306)|FATAL_ERROR|System.NullPointerException: Argument cannot be null.

Trigger.triggerTest: line 296, column 1
17:13:35.136 (4136120214)|FATAL_ERROR|System.NullPointerException: Argument cannot be null.

Trigger.triggerTest: line 296, column 1
17:13:33.239 (4136147231)|CUMULATIVE_LIMIT_USAGE
17:13:33.239|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 7 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 8 out of 150
  Number of DML rows: 8 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

17:13:33.239|CUMULATIVE_LIMIT_USAGE_END

17:13:35.136 (4136200865)|CODE_UNIT_FINISHED|triggerTest on OpportunityLineItem trigger event BeforeInsert for [new]
17:13:35.138 (4138720565)|DML_END|[44]
17:13:35.138 (4138794718)|EXCEPTION_THROWN|[44]|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, triggerTest: execution of BeforeInsert

caused by: System.NullPointerException: Argument cannot be null.

Trigger.triggerTest: line 296, column 1: []
17:13:35.139 (4139617712)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, triggerTest: execution of BeforeInsert

caused by: System.NullPointerException: Argument cannot be null.

Trigger.triggerTest: line 296, column 1: []

Class.testtest.myUnitTest: line 44, column 1
17:13:35.139 (4139630293)|FATAL_ERROR|System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, triggerTest: execution of BeforeInsert

caused by: System.NullPointerException: Argument cannot be null.

Trigger.triggerTest: line 296, column 1: []

Class.testtest.myUnitTest: line 44, column 1
17:13:33.243 (4139640210)|CUMULATIVE_LIMIT_USAGE
17:13:33.243|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 7 out of 100
  Number of query rows: 2 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 8 out of 150
  Number of DML rows: 8 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

17:13:33.243|CUMULATIVE_LIMIT_USAGE_END

17:13:35.139 (4139665696)|CODE_UNIT_FINISHED|testtest.myUnitTest
17:13:35.141 (4141215377)|EXECUTION_FINISHED
17:13:40.079 (9079920145)|EXECUTION_STARTED
17:13:40.079 (9079930309)|CODE_UNIT_STARTED|[EXTERNAL]|DuplicateDetector
17:13:40.079 (9079945678)|DUPLICATE_DETECTION_BEGIN
17:13:40.080 (9080022205)|DUPLICATE_DETECTION_RULE_INVOCATION|DuplicateRuleId:0Bmg00000004CEc|DuplicateRuleName:Account Matching|DmlType:UPDATE
17:13:40.245 (9245484318)|DUPLICATE_DETECTION_MATCH_INVOCATION_DETAILS|EntityType:Account|ActionTaken:Allow_[Alert,Report]|DuplicateRecordIds:
17:13:40.245 (9245501119)|DUPLICATE_DETECTION_MATCH_INVOCATION_SUMMARY|EntityType:Account|NumRecordsToBeSaved:1|NumRecordsToBeSavedWithDuplicates:0|NumDuplicateRecordsFound:0
17:13:40.245 (9245590964)|DUPLICATE_DETECTION_END
17:13:40.245 (9245616132)|CODE_UNIT_FINISHED|DuplicateDetector
17:13:40.247 (9247445164)|EXECUTION_FINISHED
ShotShot
>OpportunityLineItem newProdAnnual = new OpportunityLineItem (Billing_Period__c ='Annual', >OpportunityId = newOpp.Id, Service_Duration__c = 1, ServiceDate = now, End_Date__c =now, PricebookEntryId = pbe1.Id, No_Ordered__c = 1, >UnitPrice = 50, Quantity = 1); 
I dont see here ListPrice and i dont know what the field is it. 
Provide please more info.
BalajiRanganathanBalajiRanganathan
I think you have the issue as SFDC might be updating the ListPrice from PriceBook Entry only in afterinsert. Try to get the ListPrice from PriceBook Entry instead of getting it from Opportunity Line Item.
syricsyric
--Bogdan Kulyk- You can't use/edit the ListPrice field on OpportunityLineItem.  It is a standard uneditable field from PricebookEntry.  UnitPrice on PriceBookEntry sets the what ListPrice is on OpportunityLineItem.

--BalajiRanganathan - I would understand and agree with you if the trigger didn't work when I manually created an opportunity and add products in Salesforce.  Everything works the way it is suppose to.  It is only the test class that fails.  For some reason ListPrice is NULL in the test class.
BalajiRanganathanBalajiRanganathan
Hmm. its weired. I would suggest you to set the listprice in the opportunity line item constructor of your test class.
listPrice = pbe1.UnitPrice
 
syricsyric
I can't do that.  I can get an error when I try to save the class.  " SaveError: Field is not writeable: OpportunityLineItem.ListPrice "
chris.noechris.noe
Were you able to resolve this?  I am seeing the EXACT same issue.  ListPrice is not null on my before insert trigger on OpportunityLineItem object and everything works fine when running my logic through the standard UI.  When I execute this logic from a test class, I get the null reference exception.
syricsyric
It turns out that the field is not available as part of standard salesforce functionality.  I read it somewhere and I was trying to find you the link but I can't find it.  I would get error when i tried to query it as well.  What I ended up doing was making a formula field that pointed to PricebookEntry.UnitPrice.  I used this field instead of ListPrice and everything worked as it should.  I know there is probably a better option but I'm just beginer.  Hope this helps.
chris.noechris.noe
Ok, thanks.  It's odd that it works fine in the trigger when the logic executes from the standard UI but not when executing it via an Apex test class.