I have a class(batch apex) wherein i am querying(and filtering) and getting a list of records. I need to access these records inside a visual force email template by using <apex:repeat>. However this is the error i am getting when trying to save the template:

Unknown property 'core.email.template.EmailTemplateComponentController

This is the template snippet :

<apex:repeat var="i" value="{!lstDefaulters_DeliveryTeam}">

Is what i am trying to do achievable in vf email templates.

  • It seems that lstDefaulters_DeliveryTeam isn't reachable by your template. What is this field, list or relationship name? – Ilya Lepesh May 3 '16 at 4:05
  • @Ilya Lepesh lstDefaulters_DeliveryTeam is a list of records. The requirement is to iterate over this list inside the vf email template. – starhunter May 3 '16 at 8:16

If you want to display list in Visualforce email template, you should iterate through all childred related to object from which the template retrieves merge field data. Or you can include a custom component in a Visualforce email template that uses that custom controller.

Error you having after saving you snippet, describes that property doesn't exist. I think you aren't using apex:repeat properly. If you related type is relatedToType="Account" and Child Relationship Name is lstDefaulters_DeliveryTeam (assume that you have object Defaulter) repeat should access list through object:

<apex:repeat var="i" value="{!relatedTo.lstDefaulters_DeliveryTeam}">

Check your relathionship name, you could miss letter s : e.g.lstDefaulters_DeliveryTeams

In case when you are using component, make sure that lstDefaulters_DeliveryTeam has public access modifier in controller:

private final List<Defaulter> defaulters;

public findDefaulters() {
    defaulters = [select Location__c, .. from Defaulter where ..];
//should be accessed by component
public List<Defaulter> getlstDefaulters_DeliveryTeam() {
    return defaulters;

If I read your question right, you have a batch class that generates a list of records that you want to show in a VF email template

First principles:

  • The Email Template has a relatedTo (setWhatId(..)) and a recipient (setWhoId(..)).
  • Any list you generate in the VF email template has to be derivable from relatedTo or (less likely) recipient

So, you're going to need to persist the members of lstDefaulters_DeliveryTeam so that they are accessible from the value of setWhatId(..). @IlyaLepesh gives an example.

If this isn't practical, you can abandon the template altogether and just construct your own HTML in a setHtmlBody(...) method call

  • As relatedTo can only be an sobject.,that means i cannot access a list created in the batch class in the vf email template? – starhunter May 3 '16 at 9:41
  • @starhunter -- If the list created in the batch class is persisted in the database and is a child of relatedTo, then yes, the VF template can access. Otherwise, you have to construct the htmlBody yourself in the batch class without resort to using the template – cropredy May 3 '16 at 13:12

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.