You need to sign in to do that
Don't have an account?
NickDev
Test Case error: Attempt to de-reference a null object
I've started writing a Test Case so I can deploy my trigger. These are both for custom objects, however these are also on a managed package.
I am getting the following error when executing my test case:
I assume there is a perticular field which is used in an existing Trigger called pse.handleTimecardHeaderChange. However it has not been made mandatory, therefore the field is null?
If I am correct, how can I go about troubleshooting this as when I create the record through the Page it works fine and I cannot see any other fields that are populated by default.
Thanks
I am getting the following error when executing my test case:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, pse.handleTimecardHeaderChange: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object
I assume there is a perticular field which is used in an existing Trigger called pse.handleTimecardHeaderChange. However it has not been made mandatory, therefore the field is null?
If I am correct, how can I go about troubleshooting this as when I create the record through the Page it works fine and I cannot see any other fields that are populated by default.
Thanks
Try this one.
Instead of putting ids for lookup create that object in test class and then give that object's id.
@isTest
public class InsertTimecardTest {
static testmethod void insertTimecard(){
pse__Project__c project = new pse__Project__c (Name='ABC');
pse__Resource__c resource = new pse__Resource__c (Name='ABC');
pse__Assignment__c assignment = new .pse__Assignment__c (Name='ABC');
insert project;
insert resource;
insert assignment;
pse__Timecard_Header__c t = new pse__Timecard_Header__c();
t.pse__Project__c = project.id;
t.pse__Resource__c = resource.id;
t.pse__Start_Date__c = Date.newInstance(2016, 6 , 20);
t.pse__End_Date__c = Date.newInstance(2016, 6 , 26);
t.pse__Assignment__c = assignment.id;
t.CurrencyIsoCode = 'GBP';
t.pse__Monday_Hours__c = Decimal.valueOf('5.00');
t.pse__Tuesday_Hours__c = Decimal.valueOf('5.00');
t.pse__Wednesday_Hours__c = Decimal.valueOf('5.00');
t.pse__Thursday_Hours__c = Decimal.valueOf('5.00');
t.pse__Friday_Hours__c = Decimal.valueOf('5.00');
t.pse__Saturday_Hours__c = Decimal.valueOf('5.00');
t.pse__Sunday_Hours__c = Decimal.valueOf('5.00');
t.pse__Billable__c = true;
insert t;
}
Regards,
Sailee