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
renuamirenuami 

relationships inside a trigger for loop

Hi -

 

Travel__c custom Object is the related list under Opportunity. When i try to grab the AccountId from Opportunity using child relationship the value is coming as null. When i query the same in Apex explorer i am getting the results.

 

Please advise what is wrong here?

 

 

trigger test_sample on Travel__c (after update,after insert) 
{
    if(trigger.isAfter)
    {
        if(trigger.isUpdate)        
{ for(Travel__c t:Trigger.new) { system.debug('Opportunity AccountId Value '+t.Opportunity__r.Account.Id); } } } }

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jeffdonthemic2jeffdonthemic2

This blog post should explain it for you...

 

Relationship Lookup Objects in Triggers are NULL?

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

 

Author: The Salesforce Handbook

All Answers

jeffdonthemic2jeffdonthemic2

This blog post should explain it for you...

 

Relationship Lookup Objects in Triggers are NULL?

 

Jeff Douglas

Appirio, Inc.

http://blog.jeffdouglas.com

 

Author: The Salesforce Handbook

This was selected as the best answer
renuamirenuami

Thanks a bunch. Logic worked for me!!!