0

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.

2

1 Answer 1

2

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 ..
  </apex:repeat>
</apex:component>

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
  }
}
4
  • so i changed the workflow from case to Task...now these time also iam not able to get the values . Commented Aug 5, 2016 at 7:57
  • @keerthanachowdhary -- So, now you can see the Task merge fields but not the Case merge fields?
    – cropredy
    Commented Aug 5, 2016 at 15:01
  • what is the solution to get these two objects merge fields data..in need to move to visual force template?? Commented Aug 8, 2016 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
    Commented Aug 8, 2016 at 15:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .