3

I have looked through a number of different threads and haven't found any clear answers to populating a child object's value in the subject of a Visualforce Email Template.

I want to populate the Visualforce Email Template Subject line dynamically with the value of a custom object that is related to the "relatedToType" object. I have a custom component and custom class. Is there a way to pull the data from there to to subject? <messaging:emailTemplate subject="Legal Name - FWC#{!cr.Internal_MID__c} " recipientType="Contact" relatedToType="Opportunity">? Credit_Review__c has a relationship to Opportunity but Opportunity does not have a relationship to Credit_Review__c.

public class BrokerDeclineEmailTemplate {
    public Credit_Review__c cr {get;set;}
    public Id controllerValue; 

    public void init(){ 
        cr = [select Id, Opportunity__c, Internal_MID__c from Credit_Review__c WHERE Opportunity__c = :controllerValue ORDER BY CreatedDate DESC LIMIT 1];

Access parent object fields in VisualForce email template subject and VF Email Template are close but not exactly what I am looking for. Unless the only way to do it is with the URL....

1 Answer 1

3

You can't access the child that way, unfortunately. If the credit review is more of a 1:1 relationship, I'd recommend that you create a lookup field on the opportunity and populate it with the child record. You could do this via Process Builder or a trigger.

1
  • Hi @sfdcfox, I have a similar issue, Can I get the Detail Page Link in the subject of VF template ? Thanks in advance Apr 1, 2020 at 7:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .