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
randombardrandombard 

Testing if an record exists getting System.NullPointerException

specificaly I am getting this erroe for line 3 column 1

 

Please note this is all a work in progress I am trying to move all of the related records to a lead that was created via a custom button thought I would start with the tasks.

 

trigger MigrateRelatedObjects on Contact (before delete)
{
for(Contact C: trigger.new)
if([select id from Lead where Old_Contact_ID__c = :C.id].size() > 0 )
{
For(Lead L:[select id from Lead where Old_Contact_ID__c = :C.id])
    {List<Task> TaskToMove = new List<Task>();
    {For(Task T:[select id, WhoID from Task where WhoID =:C.id])
    {
    T.WhoID = L.id;
    TaskToMove.add(T);
    }

{
}
}
}
}
}

Best Answer chosen by Admin (Salesforce Developers) 
Bhawani SharmaBhawani Sharma

Use Trigger.Old instead on Trigger.New

All Answers

Bhawani SharmaBhawani Sharma

Use Trigger.Old instead on Trigger.New

This was selected as the best answer
randombardrandombard

Thanks Bhawani,

 

I dont get a null error anymore, interestingly even after I added Update TaskToMove none of the tasks got re-parented.

 

Will have to look into this more, I really apreciate the help with the null issue.

 

R