I have created a visualforce email template and I would like to display rows from a related object ORC__c
which belongs to the Account
object.
The email template would be selected like so Contacts > Joe Bloggs (contact) > Send Email > Add related to Account (field) > Select Template.
I have found that no rows are returned using the snippets I have created below. I have tried to debug the function by using a static ID on the SOQL statement, this does return rows in the template. I have also tried running the SOQL query with a static account ID in the developer console which also worked.
Email template:
<messaging:emailTemplate subject="My email subject" recipientType="Contact" relatedToType="Account">
<messaging:htmlEmailBody >
<p><apex:outputText value="{!TODAY()}" /></p>
<p>REF: <apex:outputText value="{!relatedTo.Name}" /></p>
<p>Dear {!relatedTo.Contact.Name},</p>
<c:ORCLetter_Component acctId="{!relatedTo.Id}"/>
Component:
<apex:component controller="findORCInstances" access="Global" >
<apex:attribute name="AcctId" type="Id" description="Id of the account" assignTo="{!accountId}"/>
<apex:dataTable value="{!ORCInstances}" var="wlan" styleClass="orcTableList">
<apex:facet name="header">Wireless LANs</apex:facet>
<apex:column>
<apex:facet name="header">SSID Name</apex:facet>
{!wlan.SSID__c}
</apex:column>
</apex:dataTable>
</apex:component>
Controller:
public class findORCInstances {
private final List<ORC__c> wlans;
public Id accountId {get;set;}
public findORCInstances() {
wlans = [select Name, SSID__c, NumAPs__c, Percentage_Utilisation__c from ORC__c where Client__c = ':accountId'];
}
public List<ORC__c> getORCInstances() {
return wlans;
}
public Id getActId() {
return accountId;
}
}
Note: I use client__c as an alias for Account