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
AnkehAnkeh 

Visualforce - Email Templates - Merge Fields - Cross Fields

Hi, 
This is my trigger code:
    if(trigger.isAfter && trigger.isInsert){
        List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();
        EmailTemplate emtemp = [SELECT Id from EmailTemplate WHERE Name = 'Email Notification'];
        System.debug('em temp'+emtemp);
        for (EM_Event_Team_Member_vod__c addedmem : Trigger.new) {
            
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setTargetObjectId(addedmem.Team_Member_vod__c);
            email.setTemplateId(emtemp.Id);
            email.saveAsActivity = false;
            emails.add(email);
            
        }
        
        Messaging.sendEmail(emails);
    }
This is the email template:
<messaging:emailTemplate subject="Addition of Team Member" relatedToType="EM_Event_Team_Member_vod__c">
<messaging:HTMLEmailBody >
Hi {!relatedTo.Event_vod__r.Name},
<br/><br/>
Event Name: {!relatedTo.Event_vod__r.Name}<br/>
Event City: {!relatedTo.Event_vod__r.City_vod__c}<br/>
Event Start Time : {!relatedTo.Event_vod__r.Start_Time_vod__c}<br/>
Event URL :
<br/>
</messaging:HTMLEmailBody>
</messaging:emailTemplate>

And this is the email i received:
Hi ,

Event Name:
Event City:
Event Start Time :
Event URL :


Please help me how to get values populated in the email.
Thanks.
Soyab HussainSoyab Hussain
Hi Hitesh,

You are getting blank values because in your email the parent record is blank i.e. Event_vod__e doesn't have any value.

In order to resolve your issue please follow :
Fill the values in the parent so that the email template can fetch them and populate.

If you found it useful please appreciate my efforts and mark it as the best answer.

Regards, 
Soyab