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
jonpilarski1.3914448382645588E12jonpilarski1.3914448382645588E12 

How to traverse up two objects in trigger

Hi. 

I have a custom object TargetX_SRMb__Application__c which has a master-detail relation to Contact. Contact, of course, has lookup relation to Account. In a trigger on TargetX_SRMb__Application__c I need to get Name from Account. I though I could traverse up using dot notation but always returns null. For example I tried:

 for(TargetX_SRMb__Application__c a :  trigger.new) {
  System.debug('aaccountID:'+a.TargetX_SRMb__Contact__r.Account); 
  System.debug('aaccountID:'+a.TargetX_SRMb__Contact__r.AccountId); 
  System.debug('aaccountID:'+a.TargetX_SRMb__Contact__r.Account.Id); 
}
All return null. Any and all help appreciated.

Jon

 
YuchenYuchen
In fact, trigger.new will only contain information up to one level, if you want get information from the parent also, you will need to do a query against trigger.new to find out more information. Then from the query list, you can loop through it and get the information you need.