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
CritterCritter 

Can set checkbox to false, but not true

I have this bit of code:

Project_Task__c autoTask = [Select id,auto_schedule__c from Project_Task__c where id = :theTask.id];
    	System.debug('This is the NEW **bleep** auto Task: ' +autoTask.auto_schedule__c);
    	autoTask.Auto_Schedule__c = false;
    	autoTask.Name = 'Blah blah';
    	update autoTask;

 

and all is well...

 

Should I attempt to set the 'Auto_Schedule__c' to true, I get an error..

 

10:38:39.528 (1528085000)|CODE_UNIT_FINISHED|ProjectTaskRipple on Project_Task trigger event AfterUpdate for [a0BR0000006DgHW]
10:38:39.530 (1530642000)|DML_END|[40]
10:38:39.530 (1530733000)|EXCEPTION_THROWN|[40]|System.DmlException: Update failed. First exception on row 0 with id a0BR0000006DgHWMA0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ProjectTaskRipple: execution of AfterUpdate

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

 any suggestions? I cannot suss why I am getting this error..

kcpluspluskcplusplus

Do you have the right permissions and sharing set up for the person running the transaction? It looks like your getting an error in access to the object and then returning a null reference. 

 

--KC

CritterCritter

I've never had a problem before. This is being run in a test case. AND... I can set it to true when I create the object..

 

This works...

 

Project_Task__c theTask = new Project_Task__c();
    		theTask.Project_Deliverable__c = theDeliverable.id;
    		theTask.Name = 'Critters Test Case Task';
    		theTask.Auto_Schedule__c = true;
    		insert theTask;

....


Project_Task__c autoTask = [Select id,auto_schedule__c from Project_Task__c where id = :theTask.id];
    	System.debug('This is the NEW **bleep** auto Task: ' +autoTask.auto_schedule__c);
    	autoTask.Auto_Schedule__c = false;
    	autoTask.Name = 'Blah blah';
    	update autoTask;

 

This won't...

 

Project_Task__c theTask = new Project_Task__c();
    		theTask.Project_Deliverable__c = theDeliverable.id;
    		theTask.Name = 'Critters Test Case Task';
    		theTask.Auto_Schedule__c = false;
    		insert theTask;


....


Project_Task__c autoTask = [Select id,auto_schedule__c from Project_Task__c where id = :theTask.id];
    	System.debug('This is the NEW **bleep** auto Task: ' +autoTask.auto_schedule__c);
    	autoTask.Auto_Schedule__c = true;
    	autoTask.Name = 'Blah blah';
    	update autoTask;

 

kcpluspluskcplusplus

I tried that bit of your code and it worked fine for me, could you post the whole code so I can see the whole context that's running?

 

--KC

CritterCritter

here is all of it so far...

@isTest
private class testProjectTaskRipple {

    static testMethod void myUnitTest() {
        
        //------=-=-=-=[    create project...
        Project__c theProject = new Project__c();
    		theProject.name = 'Test Case Project To Be Cloned';
    		insert theProject;
    	
    	//------=-=-=-=[    create deliverable...	
    	Deliverable__c theDeliverable = new Deliverable__c();
    		theDeliverable.deliverable_headline__c = 'This is our test data deliverable';
    		theDeliverable.Project__c = theProject.id;
    		insert theDeliverable;
    		System.debug('This is the deliverable: ' + theDeliverable.id);
    		
    	//------=-=-=-=[    create task for deliverable...
    	Project_Task__c theTask = new Project_Task__c();
    		theTask.Project_Deliverable__c = theDeliverable.id;
    		theTask.Name = 'Critters Test Case Task';
    		theTask.Auto_Schedule__c = false;
    		insert theTask;
    		
    	//------=-=-=-=[    create predecessor task...
    	Project_Task__c preTask = new Project_Task__c();
    		preTask.Project_Deliverable__c = theDeliverable.id;
    		preTask.Name = 'This is a pre task task';
    		insert preTask;
    		
    	//------=-=-=-=[    link tasks...
    	Project_Task_Project_Task__c linkTask = new Project_Task_Project_Task__c();
    		linkTask.Dependency_Type__c = 'Finish';
    		linkTask.Predecessor_Task__c = preTask.Id;
    		linkTask.Successor_Task__c = theTask.Id;
    		insert linkTask;
    		
    	//------=-=-=-=[    test object for testing...
    	Project_Task__c autoTask = [Select id,auto_schedule__c from Project_Task__c where id = :theTask.id];
    	System.debug('This is the NEW **bleep** auto Task: ' +autoTask.auto_schedule__c);
    	autoTask.Auto_Schedule__c = true;
    	autoTask.Name = 'Blah blah';
    	update autoTask;
        
    }
}

 

neophyteneophyte

From the debug log you have posted, the problem is in the after update trigger ProjectTaskRipple. Since the trigger code is not provided not sure where the error is thrown. Please check the trigger, maybe add some debugs and check where the error gets thrown.

kcpluspluskcplusplus

Agreed, can you post the trigger? The issue is not with the test method according to the debug log.

 

--KC

salvatoreovlassalvatoreovlas

it's a proble with your trigger, on the task. you should post the code.

CritterCritter

Thanks for all the replies. I was able to track down where the error was in the trigger. I had neglected to check for a null value prior to using a variable...

 

I'm all good. thanks.