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
MikeGillMikeGill 

Custom Objects in VisualForce Email Templates

Hi,

 

The online help seems to suggest that only standard objects are support for visualforce EMAIL templates.

 

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Vacancy__c"
    subject="Test"
   
    replyTo="support@acme.com">

    <messaging:htmlEmailBody >
        <html>
            <body>

            <p>Dear {!Vacancy__c.Name},</p>
       
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

Going to switch to full HTML if this is not supported.

 

Thanks 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

It is supported - we've done this in a few different projects.  It has a slightly different syntax though:

 

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Vacancy__c"
    subject="Test"
   
    replyTo="support@acme.com">

    <messaging:htmlEmailBody >
        <html>
            <body>

            <p>Dear {!relatedTo.Name},</p>
       
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 

All Answers

bob_buzzardbob_buzzard

It is supported - we've done this in a few different projects.  It has a slightly different syntax though:

 

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Vacancy__c"
    subject="Test"
   
    replyTo="support@acme.com">

    <messaging:htmlEmailBody >
        <html>
            <body>

            <p>Dear {!relatedTo.Name},</p>
       
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

 

This was selected as the best answer
MikeGillMikeGill

Strange I'm sure I tried that and it didn't work.

 

it's working - thanks

 

 

dfpittdfpitt

Hello,

 

What about using custom objects in an apex:repeat call, is that allowed?

 

<apex:repeat var="cx" value="{!relatedTo.CustomObject__c}">

 

I get the following error: Invalid field CustomObject__c for SObject Cita__c

skompoltskompolt

Hi Bob,

 

Something you cannot do unless you know a trick is to use a custom email field in a visualforce email template.  In work flows you can specify a customemail field to be used in an email template. HTML email templates can utilize these work flows.  

 

You can specify for example:

 

<messaging:emailTemplate recipientType="Email Field"
    relatedToType="Vacancy__c"
emailfield ="email" subject="Test" replyTo="support@acme.com"> <messaging:htmlEmailBody > <html> <body> <p>Dear {!relatedTo.Name},</p> </body> </html> </messaging:htmlEmailBody> </messaging:emailTemplate>

loginaditya1.3936441421958025E12loginaditya1.3936441421958025E12
Hi dfpitt,

try

 <apex:repeat var="cx" value="{!relatedTo.CustomObject__r}">
It works.

Thanks
Aditya