Scenario - Case object has a custom child object (sample_case_child__c). That child object will have some file attachment.

When a case is sent for approval, the email sent out to approver should show the link to download the attachment on the child object.

I am using visualforce email template for this.

Template has a component, which does the work of querying for attachment and putting the output link.

My problem is, in the email that is sent, there is no hyperlink. The text "Download here" appears, but it is not a hyperlink. What am i doing wrong?

Code for VF template -

<messaging:emailTemplate subject="test" recipientType="User" relatedToType="Case">
<messaging:htmlEmailBody >
     <c:showChildObject parentCaseId="{!relatedTo.Id}"/> 

Code for the component showChildObject -

<apex:component access="global" controller="showChildObjectController">
<apex:attribute name="parentCaseId" type="Id" assignTo="{!currentCaseId}" description="test description"/>
<apex:outputLink value="{!linkForAttachment}"> Download here</apex:outputLink>

Controller for the component -

public class showChildObjectController{
    public Id currentCaseId {get; set;}

    public String getlinkForAttachment(){
      sample_case_child__c result = [Select Name, Amount__c, (Select Id, Name from Attachments) from sample_case_child__c Where Case__c=:currentCaseId LIMIT 1];
      Attachment temp = result.Attachments[0];
      String link = '{!URLFOR($Action.Attachment.Download,'+ String.valueOf(temp.Id)+')}';
      return link;
  • This trick of generating the merge field (URLFOR) in the controller and expecting the VF component to then evaluate it I don't think is going to work. You should generate the full URL in the controller – cropredy Oct 14 '15 at 16:56

There is apparently some error with outputLinks in html email templates. Try to use anchor tag instead like this:

<apex:component access="global" controller="showChildObjectController">
<apex:attribute name="parentCaseId" type="Id" assignTo="{!currentCaseId}" description="test description"/>
<a href="{!linkForAttachment}">Download here</a><br/>


The first line works for me

  • Patiatus - Its still not working for me. It just shows the text "Download here", no hyperlink Did you try to put that component in VF email template? or did you test it in a VF page? I am just wondering if page and email template have different rules – user21352 Oct 14 '15 at 14:58
  • @user21352 - let me be more precise: I replaced line <apex:outputLink value="{!linkForAttachment}"> Download here</apex:outputLink><br/> by <a href="{!linkForAttachment}">Download here</a> Then put that component in VF email template, then clicked on "Send Test and Verify Merge Fields", selected user and case with related sample case childs which have attachments (otherwise there will be run-time exception) and received email with hyperlink. Are you sure you are correctly using this template? Did you try to click "Send Test and Verify Merge Fields" button on Email Template definition? – Patlatus Oct 16 '15 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.