I'm new to Apex and Code...

A trigger from a managed package is causing my test class to fail. Here's the code for the trigger causing the error:

trigger RAPID_SVMXC_BeforeInsertUpdateDelete_WorkDetails on SVMXC__Service_Order_Line__c (before insert, before update,before delete) {

Activate_Timesheet__c Activate_Timesheet   = new Activate_Timesheet__c();  // name of Custom Setting
Activate_Timesheet = Activate_Timesheet__c.getValues('TimesheetState');  // grab the specific setting

if (Activate_Timesheet.Enable_Timesheet__c==true || RAPID_SVMXC_TimesheetUtils_UT.TimesheetUtilsTest==true)
    if (trigger.isDelete) 

The error message is:

caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.RAPID_SVMXC_BeforeInsertUpdateDelete_WorkDetails: line 7, column 1: []

Line 7 in that trigger is: if (Activate_Timesheet.Enable_Timesheet__c==true || RAPID_SVMXC_TimesheetUtils_UT.TimesheetUtilsTest==true)...

I can't figure out why it's causing this error if "Activate_Timesheet__c" is a Custom Setting, why is a missing lookup field on my record insert causing that?

1 Answer 1


You need to create custom setting in your test class.

Insert new Activate_Timesheet__c (field__c = value);

  • 1
    And the reason for this is that Custom Setting data in an org is not available in unit tests. If you (OP) don't create the data, you'll get null back from Activate_Timesheet__c.getValues('TimesheetState');. That was the cause of the NPE you were getting.
    – Derek F
    Nov 8, 2017 at 19:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .