0

I have a Visualforce Email Template which is as follows

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Case"
    subject="Test">
...
<apex:repeat first="0" rows="1" value={!ralatedTo.workorders} var="worder">
Click <a href = "{!$Lable.myURL}?workorderId={!worder.Id}">here.</a>
</apex:repeat>
...
</messaging:emailTemplate>

Using the <apex:repeat> I am getting one Workorder record data which I need to pass in the URL. I need the Workorder here which is last created (1st result when Workorder query is done with order by creation date in desc). Is there a way I can get it without controller class?

Also, I tried the solutions with the controller class. I am creating a controller class and an apex component but how can I pass the data from apex component to the email template as I don't want to display it but reuse the value?

1 Answer 1

1

Without a way to specify a controller or extension in the template itself, anything you do in the component will be constrained to that component. You also can't reliably use <apex:variable> within an <apex:repeat>, so there's no reliable way to get the work order that you're looking for. A better solution would be to place the entire contents of the email in the component, where the template itself is only a placeholder:

<messaging:emailTemplate recipientType="Contact" relatedToType="Case" subject="Test">
  <c:workorderEmailTemplate caseId="{!relatedTo.Id}" contactId="{!recipient.Id}" />
</messaging:emailTemplate>

This will give you the control you're looking for.

1
  • Thanks! It resolved my issue. I didn't put the full template in the component but just the link. Mar 1, 2021 at 20:48

You must log in to answer this question.

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