function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NalinakuNalinaku 

Opportunity line item test class trigger error

Hi, 
I am running a test class on opportunity, which is inserting opportunity line items in couple of methods and everytime its trying to insert the Opp line item I get the below error from the trigger. 
It looks like Opp line item is getting inserted but trigger is failing them.

The line number which shows in the error is again the update/insert of opp line item which is failing. 

I checked the error Attempt to dereference null object, but I see new object is instatiated whereever dml is being performed. 

I checked the UserAssignHelper.checkLineItems at line 13 which is getting values from custom settings and I see values exists there. 

Please suggest. 
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PSLR_OpportunityLineItem: execution of AfterInsert

caused by: System.DmlException: Update failed. First exception on row 0 with id 00k2i000003lJCDAA2; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, PSLR_OpportunityLineItem: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Class.UserAssignHelper.checkLineItems: line 13, column 1
Class.PSLR_OpportunityLineItemHandler.updateOppOwnerBasedOnLineItemPricingType: line 122, column 1
Trigger.PSLR_OpportunityLineItem: line 50, column 1: []

Class.PSLR_OpportunityLineItemHandler.NoOfLineItem: line 28, column 1
Trigger.PSLR_OpportunityLineItem: line 42, column 1: []

 
Best Answer chosen by Nalinaku
Agustin BAgustin B
Hi Nalinaku,for test classes you will have to create the object and also the custom settings before inserting your record.
Please try doing that and you should get no error.

if it helps please mark as correct as it may help others.
if not please provide the entire code to help you more

All Answers

Agustin BAgustin B
Hi Nalinaku,for test classes you will have to create the object and also the custom settings before inserting your record.
Please try doing that and you should get no error.

if it helps please mark as correct as it may help others.
if not please provide the entire code to help you more
This was selected as the best answer
NalinakuNalinaku
Thanks Agustin. I created custom settings in test class and then on I am not getting this error, but I ll have to work on code coverage. Thanks though.