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
kladizkovkladizkov 

Accessing 'Name' of a lookup relationship

Hi,

 

In my contact, I have a custom lookup field called 'Favorite Place'. I have a trigger that fires before record update. And, in the Apex class method I'm trying to mail the 'Favorite Place' of that contact. I used the below code

 

mail.setHTMLBody('Place: ' + c.Favorite_Place__r.Name);

 

But, it says 'Place:null' in the email. But, in contact the field 'Favorite Place' has been correctly populated as 'Hawaii'. Any idea, what i'm doing wrong here.? Please help.

 

 

aalbertaalbert
The relationship fields are not populated by default on a trigger. You need to query explicitly for related field values.