+ Start a Discussion
Rocio VivancoRocio Vivanco 

Email is not rendering table of contacts with IF condition using visualforce component and apex controller class

Hi all,

I am trying to make a rendering work with a combination of my email template, a visualforce component and an apex, controller class.

My email template has as RelatedToType the object Opportunity. In the email there should be displayed the most important account data (Account lookup in the object Opportunity). It should also show the contacts to this account, which have their Codigo_JDE__c empty.

What I would like to achieve is to display these contacts only if there are any, if not, the part to display the table of these contacts, should not be displayed.

Here is the part in my email template where I am invoking the Visualforce component:
<c:AccountContacts accountIdValue="{!relatedTo.AccountId}"/>

Here is my Visualforce component:
<apex:component access="global" controller="AccountContacts">

    <apex:attribute name="accountIdValue" type="String" description="This is the Id of the account" assignTo="{!accountId}" access="global" />
    <apex:outputPanel rendered="{!IF(AND(NOT(ISBLANK(conList)),conList.size>0),'Yes','No')}">  
    <tr >
        <td >
          Contact data:<br/><br/>
                <th>FIRST NAME</th> 
                <th>LAST NAME</th>
           <apex:repeat value="{!Cons}" var="pos">


I am using this part in the code:
to render only if the conList is not empty. The conList is declared in the apex class:
global with sharing class AccountContacts{
    global String accountId{get;set;}
    global List<Contact> conList{get;set;}

    global account account{
        get {
          Account = [Select Id, name from Account where id =: accountId];
          return account; }
    global AccountContacts(){

    global List<Contact> Cons{
            List<Contact> conList = [SELECT Id,FirstName,LastName,Codigo_JDE__c FROM Contact WHERE AccountId=:accountId and Codigo_JDE__c = null];
            Boolean display = false;
            if(conList != null && conList.size()>0){

            return conList;
    global String NewLine {
        get { return '\r\n'; }
Unfortunately when I receive the email, even when there are contacts with Codigo_JDE__c empty, they are not being displayed (the table is not being displayed), why?.
I would appreciate if someone could give me tips where to correct this, as I have been spending hours trying to amend this without success.

Eric PepinEric Pepin
For this block of code:


You may need to change Yes/No to True/False.
Rocio VivancoRocio Vivanco
Thanks Eric for your answer. I changed it to true and false, but it didn't work either.