You need to sign in to do that
Don't have an account?
WeylandYutanie
Must be a silly mistake
Hi, I am getting the following error when trying to update a field on the before deletion of an object:
LeavingTheLine: execution of BeforeDelete
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.LeavingTheLine: line 5, column 9
I must be missing something really obvious. Any help appreciated.
Weyland
Code:
1 trigger LeavingTheLine on Place_in_Line__c (before delete)
2 {
3 for (Place_in_Line__c SpotInLine : Trigger.old)
4 {
5 SpotInLine.Group_Leader_Line__r.Number_of_People_in_Line__c = 1;
6 }
7 }
In your trigger , you are trying to access a related object's field directly from trigger.old list's item. Triger.old only can give you values from the current object field only not from related objects field values.
SpotInLine.Group_Leader_Line__r.Number_of_People_in_Line__c = 1;
This part is null
SpotInLine.Group_Leader_Line__r
So when you try to fetch Number_of_People_in_Line__c from ths null value it shows you attempt to deref a null object error.
There are certain other things also that i would like to tell you
1)You can not modify a trigger.old list item in before delete object it thorws you this error if you do it
System.FinalException: Record is read-only
Your trigger sould be like this
All Answers
In your trigger , you are trying to access a related object's field directly from trigger.old list's item. Triger.old only can give you values from the current object field only not from related objects field values.
SpotInLine.Group_Leader_Line__r.Number_of_People_in_Line__c = 1;
This part is null
SpotInLine.Group_Leader_Line__r
So when you try to fetch Number_of_People_in_Line__c from ths null value it shows you attempt to deref a null object error.
There are certain other things also that i would like to tell you
1)You can not modify a trigger.old list item in before delete object it thorws you this error if you do it
System.FinalException: Record is read-only
Your trigger sould be like this
Thank you for the response. I think my understanding of trigger.old and trigger.new isn't quite right. If I want to access parameters from the object that caused the trigger, can I do something like the following? Best regards, Weyland.