Hi i have two objects case and task,in between these am created lookup relationship now in the email template I was referring the both task fields and case fields,when I am firing a workflow the merge fields are not fetching the values...... Example

Hi {!Case.Name},{!Case.family name}

Hello {!Task.firstname}{!Task.LastName}

can u please give any suggestion that I am using the correct Syntax.


If workflow is on Case, then it is impossible using Text or HTML emails to show children record merge fields (i.e. Tasks) because the target object in scope for the email template is the target object of the workflow

To show Tasks - and since there can be more than one Task for a Case, you'll need to think about your business logic as to which task or tasks to show. Once having done that, you will need to:

  • Make the email template a VF email template
  • Create a custom component to show the related task (or tasks). The custom component uses a custom controller to fetch the related task(s) given a Case.Id that is passed to the component.

VF template

... markup for Hi! ...
<c:taskList caseId={!Case.Id}/> <!-- show tasks here in email body -->
... more markup, if any -- e.g. a footer

VF component

<apex:component access="global" controller="TasksController">
  <apex:attribute name="caseId" type="ID" required="true" assignTo={!csId}/>

  <apex:repeat value="{!tasks}" var="t">  <!-- can also use dataTable or straight <table> -->
     .. markup for a Task row ..

Component controller

public class TasksController {
  public ID csId {get; set;}  // gets value before getTasks() is called
  public Task[] getTasks() {
    return csId != null
            ? [select id, ... from Task where whatId = :csId ...]
            : new List<Task>();  // avoids preview exception
  • so i changed the workflow from case to Task...now these time also iam not able to get the values . Aug 5 '16 at 7:57
  • @keerthanachowdhary -- So, now you can see the Task merge fields but not the Case merge fields?
    – cropredy
    Aug 5 '16 at 15:01
  • what is the solution to get these two objects merge fields data..in need to move to visual force template?? Aug 8 '16 at 5:26
  • @keerthanachowdhary - Unfortunately, because Task has polymorphic parent (Case, Contact, Account, etc.) you can't get Case fields if Task is the target object so, yes, VF email template with a VF custom component/controller
    – cropredy
    Aug 8 '16 at 15:11

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.