+ Start a Discussion

Is it possible to use URLFOR function in visualforce email template?

Hi ,


I am trying to create a visualforce template on an Task to send email to Users when insertion of task happens (used a trigger).

Please find the code as  of the visualforce template referred by the trigger as below :

<messaging:emailTemplate subject=" Task Created" recipientType="User" relatedToType="Task" >
<messaging:htmlEmailBody >
   Task Status      :  {!relatedTo.Status}<br/>
   Task Subject     :  {!relatedTo.Subject} <br/>
   Task Type        :  {!relatedTo.Type} <br/>
   Task Description :  {!relatedTo.Description}<br/>
   Polos Order      :  {!relatedTo.Order__c} <br/>  
   Task id          :  {!relatedTo.id}<br/>
  <apex:outputLink value="/{!relatedToid}">
         Please click on link to View task in salesforce!


Please Note,I have to  put a link(URL) of the Task. In the email to be sent so that the user receiveing it can click on the link and open up the task view.

There are two issues that I am facing  :


1)  All the task (relatedTo) merge fields are coming balnk in the email sent to users.


2) I want to use URLFOR function with the email template for outputlink but this seems to be thoring an exception : invalid paramater for URLFOR

<apex:outputLink value="{!urlFor($Action.Task.View, relatedTo.id)}">



PS :

1) I cannot seem to use the visualforce component for the same becoz I am not getting relatedTo.Id to pass to VF component.

2)Oddly this is happening only when actual trigger is fired and not when I click on send test and verify merge fields.


Could some body please help me with this issue.

Thanks in advance for help!!!

I think you need:

<apex:outputLink value="{!urlFor($Action.Task.View, $ObjectType.task, relatedTo.id)}">


I have tried the option suggested by you but Salesforce is not letting me save the template due to following error:


Error: Incorrect argument type for function 'urlFor()'.

It's probably just syntax... are you referring to the documentation?