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

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
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
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.