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
Christopher TaylorChristopher Taylor 

I am receiving an apex error when updating an opportunity for triggers that havent been edited since 2013.

I receive the following error when attempting to create new opportunities.  I can update existing ones just fine.  The apex trigger in mention hasn't been updated since 2013.

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger Opportunity_UpdateNextTask caused an unexpected exception, contact your administrator: Opportunity_UpdateNextTask: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.Opportunity_UpdateNextTask: line 25, column 1
Lalit Mistry 21Lalit Mistry 21
Hi Lee,

Looking at the error message, it seems one of the variable is used without actually been intialized first. In order to help you further on this error, it will be good if you can post small snippet of the trigger (Opportunity_UpdateNextTask) from line 20 to 30.
Christopher TaylorChristopher Taylor
User-added image
The code cas not been updated since its creation in 2013.  
Lalit Mistry 21Lalit Mistry 21
Looks like the one of the open task on opportunity that you are updating do not have the subject populated on it.
You can either update the task to have subject populated or modify the line 25 as below
if(T.Subject != null)
	opp.Next_Task_Subject__c = T.Subject.left(60);

 
Christopher TaylorChristopher Taylor
The strange thing is this hadn't been hapening before, and we haven't made any changes to the apex code since 2013.  In addition, converting leads to opportunities works, as well as updating existing opportunities.  The only timie we get this error is when we create new opportunities (Shouldnt have any tasks associated with it at that point anyway).  
Lalit Mistry 21Lalit Mistry 21
Do you have any process that creates a task on opportunity insert, especially via apex code or process builder, because thats the only place where you can create tasks without actually providing a subject. Otherwise its just good to have the trigger updated to have logic just like you have it for task description on line 22.