You need to sign in to do that
Don't have an account?

Simple (before delete) Trigger
Hi there,
I have two objects: (the standard) Contact and a CustomObject. The relationship between the two is a lookup-field on the Contact, named "CustomObjectID".
I have a checkbox on the CustomObject-record; this checkbox shows whether a Custom Object has a Contact related to it.
Now, when I delete a Contact, I want the checkbox on the related Custom Object to be unchecked.
I currently use this apex trigger:
trigger CustomObjectDelete on Contact (before delete) {
for (Contact c : Trigger.old) {
c.CustomObject__r.Checkbox__c = false;
}
}
But it gives error: "System.NullPointerException: Attempt to de-reference a null object:"
Many many thanks in advance !
KR, Valentijn
Hi, the problem is that the trigger doesn't drill into the relationships. So you have to select them manually. Will be something like this:
Let me know if that was what you were looking for.
Regards,
J.
All Answers
in trigger instance you cant access the refernce fields .. u need to get all the deleted contacts first and get all the related custom object records and update as u required...
Thanks ! That makes sense.
Is it difficult to create a trigger like that (including the queries) ? Do you have any documentation/links on this ?
Many thanks in advance !
Hi, the problem is that the trigger doesn't drill into the relationships. So you have to select them manually. Will be something like this:
Let me know if that was what you were looking for.
Regards,
J.
GREAT !!! THANKS !!!!
No problem :)
J.