[SalesForce] Visualforce Email Template for custom fields

I have a custom object called Feedback that has a name field. I have set up an email alert every time a feedback is created. But I'm unable to add a link back to the feedback created(in salesforce) in the email template. Following is my code…

<messaging:emailTemplate subject="New Feedback Created" recipientType="User"       
 relatedToType="account">
  <messaging:plainTextEmailBody >
   Dear {!recipient.name},

    A new feedback created. Check now!
    Click https://na15.salesforce.com/{!relatedTo.Feedback__c.name}

    Regards,
    {!recipient.name}
 </messaging:plainTextEmailBody>
 </messaging:emailTemplate>

Is it possible to add a link without adding a controller? Please guide me. Thanks

Best Answer

With the email templates, you need to use the sObject which the email template will be related to. In this case, if you have an email template that you're going to use with your "Feedback" custom object, your email template should be related to Feedback__c rather than Account (see relatedToType parameter).

Then when you're merging fields, the variable {!relatedTo} represents your sObject and in your case will be {!relatedTo.Name} if you want to display the feedback record name in your email.

Related Topic