[SalesForce] “recipientType” & “relatedToType” in VF Email template

I wanted to create an email template that can be used as custom javascript button on custom object.

So i have 2 custom object : Obj1__c & Obj2__c. Neither of these objects are directly related to any standard object. Obj1(master) has m/d relationship with Obj2. Now i have create a custom javascript button on Obj1 to send email.

.toAddresses is set to "{!Obj1__c.Email__c}";

Now I wanted to crate an vf email template to show all realted records (Obj2)data in email template. But not sure about the what values should i select for "recipientType" & "relatedToType"

All the online vf templates examples have standard object as Recipient Type hence confused.

Thanks for your time!

Best Answer

Since based on Obj1, you want to display Obj2 data in the template, so approach is:

First, the recipientType also called the WhoID and secondly the relatedToType also refered to as the whatID in regular email templates. In addition, a replyTo address can be defined, so that anyone replying to the email can reply back to this address.

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Obj1__c"
    subject="Display records related to: {!relatedTo.name}"
    replyTo="support@acme.com">

If you want to access Obj2 fields, use this to verify the correct relationship name from workbench (if you have any confusion)

<apex:repeat var="cx" value="{!relatedTo.Obj2__r}">
Related Topic