You need to sign in to do that
Don't have an account?
avimeir
Problem with triggers + relationships
Hi,
I have an object that creates association of two custom objects: Reservation and Room. I am trying to do something when a new association is created. This is the code I have:
trigger handleNewRoomResaAssociation on ReservationRoomAssociation__c (after insert) { for (ReservationRoomAssociation__c assoc : Trigger.New) { System.debug(assoc.Room__r.Name); } }
The debug returns null, as if there is no Room__c object associated. What am I doing wrong?
Thanks
You probably need to store these in a map keyed by the id so that you can retrieve the appropriate record. Something like:
All Answers
If you need values from related records you have to query those back yourself. The record in the trigger will only have the ID field populated in assoc.Room__c.
How do I do this?
Been struggling with related fields for 2 days now and I am starting to go crazy :P
You probably need to store these in a map keyed by the id so that you can retrieve the appropriate record. Something like: