+ Start a Discussion
Mike @ BlackTabMike @ BlackTab 

CANNOT_INSERT_UPDATE_ACTIVE_ENTRY Argument 1 cannot be null External entry point: []

	//RollUpTime Trigger Test
	static testMethod void testRollUpTime(){
		Project2__c project = new Project2__c();
		project.Name = 'Test Project';
		insert project;
		
		Milestone_NEW__c milestone = new Milestone_NEW__c();
		milestone.Name = 'Test Milestone';
		milestone.Project__c = project.Id;
		insert milestone;
		
		Deliverable__c deliverable = new Deliverable__c();
		deliverable.Name = 'Test Deliverable';
		deliverable.Milestone_NEW__c = milestone.Id;
		deliverable.Billable_Hours_Consumed__c = 0;
		deliverable.Billable_Hours_Planned__c = 0;
		insert deliverable;
		
		ToDo2__c todo = new ToDo2__c();
		todo.Deliverable__c = deliverable.Id;
		todo.Name = 'Test Todo';
		todo.Billable__c = TRUE;
		todo.Hours_Consumed__c = 10.5;
		insert todo;
		
		ToDo2__c todo2 = new ToDo2__c();
		todo2.Deliverable__c = deliverable.Id;
		todo2.Name = 'Test Todo2';
		todo2.Billable__c = FALSE;
		todo2.Hours_Consumed__c = 10.5;
		insert todo2;
		
		todo.Hours_Consumed__c = 15;
		todo2.Hours_Consumed__c = 15;
		update todo;
		update todo2;
		
		delete todo;
		delete todo2;
	}

 Trigger:

trigger RollUpTime on ToDo2__c (after insert, after update, after delete) {
    
    ToDo2__c todo = new ToDo2__c();
    
    if(Trigger.isInsert || Trigger.isUpdate){
        todo = Trigger.new[0];
    }else if(Trigger.isDelete){
        todo = Trigger.old[0];
    }
    
    if(todo.Deliverable__c != null){
    Deliverable__c deliverable = [SELECT id, Billable_Hours_Consumed__c, Billable_Hours_Planned__c, Non_Billable_Hours_Consumed__c, Non_Billable_Hours_Planned__c, Cost_To_Client__c FROM Deliverable__c WHERE id = :todo.Deliverable__c];
    
    //add related todo's time to related deliverable
    if(Trigger.isInsert || Trigger.isUpdate){
        if(todo.Billable__c == True){
            Decimal billableHoursConsumed = deliverable.Billable_Hours_Consumed__c;
            Decimal billableHoursPlanned = deliverable.Billable_Hours_Planned__c;
            Decimal costToClient = deliverable.Cost_To_Client__c;
        
            deliverable.Billable_Hours_Consumed__c = billableHoursConsumed + todo.Hours_Consumed__c;
            deliverable.Billable_Hours_Planned__c = billableHoursPlanned + todo.Hours_Planned__c;
            deliverable.Cost_To_Client__c = costToClient + todo.Cost_To_Client__c;
        }else{
            Decimal nonBillableHoursConsumed = deliverable.Non_Billable_Hours_Consumed__c;
            Decimal nonBillableHoursPlanned = deliverable.Non_Billable_Hours_Planned__c;
        
            deliverable.Non_Billable_Hours_Consumed__c = nonBillableHoursConsumed + todo.Hours_Consumed__c;
            deliverable.Non_Billable_Hours_Planned__c = nonBillableHoursPlanned + todo.Hours_Planned__c;
        }
    }else if(Trigger.isDelete){
        if(todo.Billable__c == True){
            Decimal billableHoursConsumed = deliverable.Billable_Hours_Consumed__c;
            Decimal billableHoursPlanned = deliverable.Billable_Hours_Planned__c;
            Decimal costToClient = deliverable.Cost_To_Client__c;
        
            deliverable.Billable_Hours_Consumed__c = billableHoursConsumed - todo.Hours_Consumed__c;
            deliverable.Billable_Hours_Planned__c = billableHoursPlanned - todo.Hours_Planned__c;
            deliverable.Cost_To_Client__c = costToClient - todo.Cost_To_Client__c;
        }else{
            Decimal nonBillableHoursConsumed = deliverable.Non_Billable_Hours_Consumed__c;
            Decimal nonBillableHoursPlanned = deliverable.Non_Billable_Hours_Planned__c;
        	Decimal costToClient = deliverable.Cost_To_Client__c;
        
            deliverable.Non_Billable_Hours_Consumed__c = nonBillableHoursConsumed - todo.Hours_Consumed__c;
            deliverable.Non_Billable_Hours_Planned__c = nonBillableHoursPlanned - todo.Hours_Planned__c;
            deliverable.Cost_To_Client__c = costToClient = costToClient - todo.Cost_To_Client__c;
        }
    }
    
    update deliverable;
    }
}

 The error occurs when inserting a new todo, and i'm having trouble figuring out what's causing it. Thanks

:) :) :) :) :):) :) :) :) :)

I think you need to insert each and every columns you have defined in SOQL query.  because you are retrieving values which doesn't exist

 

deliverable.Name = 'Test Deliverable';
deliverable.Milestone_NEW__c = milestone.Id;
deliverable.Billable_Hours_Consumed__c = 0;
deliverable.Billable_Hours_Planned__c = 0;

deliverable.Non_Billable_Hours_Consumed__c = 0;

deliverable.Non_Billable_Hours_Planned__c = 0;

deliverable.Cost_To_Client__c = 0;

 

insert deliverable;