+ Start a Discussion
Cameron SeitzCameron Seitz 

Test Class Failing To Insert

I'm receiving an error when attempting to run my test class. jstcl__Placement__c is a lookup who's parent is ts2__Placement__c which is why I construct it initially.

Error:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ts2.Placement: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.ts2.Placement: line 14, column 1: []
 
@istest
public class placementTimecardAuditFlagTest{
    
     static testMethod void myTest() {
         
		Contact a= new Contact(Lastname = 'Test');
		insert a;
        
        ts2__Placement__c b= new ts2__Placement__c();
        insert b;
 
// Create common test timesheets
        List<jstcl__TG_Timesheet__c> testTimesheets = new List<jstcl__TG_Timesheet__c>();
        for(Integer i=0 ;i <200;i++) { 			
            testTimesheets.add(new jstcl__TG_Timesheet__c(jstcl__Week_Ending__c = Date.today()-15, jstcl__Consultant__c = a.Id,jstcl__Placement__c=b.Name));
        }
        insert testTimesheets;       

         
// Create common test placements
        List<ts2__Placement__c> testPlacements = new List<ts2__Placement__c>();
        for(Integer i=0 ;i <200;i++) {
            testPlacements.add(new ts2__Placement__c(ts2__Status__c = 'Active'));

        }
        insert testPlacements;        
//Testing
    Test.startTest();  
        
      placementTimecardAuditFlag obj = new placementTimecardAuditFlag();
        DataBase.executeBatch(obj); 
        
        Test.stopTest();
        System.AssertEquals(database.countquery('SELECT TCEDaudit__c FROM ts2__Placement__c'),1);
    }}




 
Maharajan CMaharajan C
Hi Cameron,

Check the Trigger in your org. Trigger name is like ts2.

In that trigger line 14 check did you assign any value to record which is process in before context.

Before assign the value check the null like below.

If(AccountId != null)
{
 Con.Account= AccountId;
}


Or please post the trigger so that we can help:

Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Raj
Cameron SeitzCameron Seitz
It's actually a managed package so I can't see it. Is there something that I can do to get around it?