function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
b.gonzalezb.gonzalez 

Help with VF email template?

I need some assistance. I am trying to write a VF email template that displays only the campaign members when the custom checkbox field called Notification Needed equals "True".  Listed below is the VF email template. 

In the template I wrote: <apex:repeat var="cm" value="{!relatedTo.CampaignMembers}," Rendered="{!IF(NOT(ISBLANK(!relatedTo.CampaignMembers.Notification_Needed__c)),true, false)}"> But it is not correct. 

I am recieving the following Error: Unknown property 'VisualforceArrayList.Notification_Needed__c'

I appreciate any help you can offer. Thanks!

 
<messaging:emailTemplate subject="Marketing Generated Named Account Prospects - NA-Eastern Region" recipientType="User" relatedToType="Campaign">
<messaging:htmlEmailBody > 
     <html>
        <body>
         <STYLE type="text/css">
               TH {font-size: 14px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center }
               TD  {font-size: 14px; font-face: verdana }
               TABLE {border: solid #CCCCCC; border-width: 1}
               TR {border: solid #CCCCCC; border-width: 1}
         </STYLE>
                  <font face="arial" size="3"></font>
        <p>Dear Jim Michelson,</p>
        <p>New marketing generated named account prospect(s) have been assigned to you and are now available for follow up. In addition, attached for your use is a follow up template.</p> 
        <p>To view the prospects that have been assigned to you click on the report link below.</p>
        <apex:outputLink value="https://qlogic--sandbox.cs7.my.salesforce.com/00OM0000000h74W">Named Account Prospects Eastern Region </apex:outputLink><br></br>

<table border="1"></table>
<tr></tr>
<table border="0" >
                 <tr >
                     <th>Prospect First Name</th><th>Prospect Last Name</th><th> Title </th><th> Phone </th><th> Email </th><th> State </th><th> Country </th><th>Company Name</th><th> Marketing Source</th>
                 </tr>
    <apex:repeat var="cm" value="{!relatedTo.CampaignMembers}," Rendered="{!IF(NOT(ISBLANK(!relatedTo.CampaignMembers.Notification_Needed__c)),true, false)}">
     <tr>
           <td>{!IF(cm.contactId != null,cm.contact.FirstName,cm.lead.firstname)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.LastName,cm.lead.lastname)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Title,cm.lead.Title)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Phone,cm.lead.Phone)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Email,cm.lead.Email)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.MailingState,cm.lead.State)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.MailingCountry,cm.lead.Country)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Account.Name,cm.lead.Company)}</td>
           <td>{!cm.Campaign.Name}</td>
           </tr>
    </apex:repeat>                     
       </table>
       <p>Sincerely,</p> 
       <p>System Administrator</p>
        </body>
    </html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

 
Best Answer chosen by b.gonzalez
Dario BakDario Bak
You are trying to get the attribute from the array itself. try this: !relatedTo.CampaignMembers[0].Notification_Needed__c

All Answers

Dario BakDario Bak
You are trying to get the attribute from the array itself. try this: !relatedTo.CampaignMembers[0].Notification_Needed__c
This was selected as the best answer
b.gonzalezb.gonzalez
Hi Dario,

Thank you! I tried:  !relatedTo.CampaignMembers[0].Notification_Needed__c but now I am recieving the following error: Unknown property 'String.contactId'.
 
<messaging:emailTemplate subject="Marketing Generated Named Account Prospects - NA-Eastern Region" recipientType="User" relatedToType="Campaign">
<messaging:htmlEmailBody > 
     <html>
        <body>
         <STYLE type="text/css">
               TH {font-size: 14px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center }
               TD  {font-size: 14px; font-face: verdana }
               TABLE {border: solid #CCCCCC; border-width: 1}
               TR {border: solid #CCCCCC; border-width: 1}
         </STYLE>
                  <font face="arial" size="3"></font>
        <p>Dear Jim Michelson,</p>
        <p>New marketing generated named account prospect(s) have been assigned to you and are now available for follow up. In addition, attached for your use is a follow up template.</p> 
        <p>To view the prospects that have been assigned to you click on the report link below.</p>
        <apex:outputLink value="https://qlogic--sandbox.cs7.my.salesforce.com/00OM0000000h74W">Named Account Prospects Eastern Region </apex:outputLink><br></br>

<table border="1"></table>
<tr></tr>
<table border="0" >
                 <tr >
                     <th>Prospect First Name</th><th>Prospect Last Name</th><th> Title </th><th> Phone </th><th> Email </th><th> State </th><th> Country </th><th>Company Name</th><th> Marketing Source</th>
                 </tr>
    <apex:repeat var="cm" value="{!relatedTo.CampaignMembers}," Rendered="{!IF(NOT(ISBLANK(!relatedTo.CampaignMembers[0].Notification_Needed__c)),true, false)}">
     <tr>
           <td>{!IF(cm.contactId != null,cm.contact.FirstName,cm.lead.firstname)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.LastName,cm.lead.lastname)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Title,cm.lead.Title)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Phone,cm.lead.Phone)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Email,cm.lead.Email)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.MailingState,cm.lead.State)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.MailingCountry,cm.lead.Country)}</td>
           <td>{!IF(cm.contactId != null,cm.contact.Account.Name,cm.lead.Company)}</td>
           <td>{!cm.Campaign.Name}</td>
           </tr>
    </apex:repeat>                     
       </table>
       <p>Sincerely,</p> 
       <p>System Administrator</p>
        </body>
    </html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>

 
Dario BakDario Bak
Dario to the rescue... Try with this!
 
cm.contact.id

If this makes it work, please choose as best response!
 
b.gonzalezb.gonzalez
Hi Dario,

I am not good with writing code and not sure where to place cm.contact id. Please excuse my lack of knowledge. Can you please show me where I should place cm.contacct.id ?

Beth
Dario BakDario Bak
replace "cm.contactId" with "cm.contacct.id" and let me know how it goes.

Dario
b.gonzalezb.gonzalez
I recieved a syntex error. Syntax error. Found 'cm.contact.id' 
 
<messaging:emailTemplate subject="Marketing Generated Named Account Prospects - NA-Eastern Region" recipientType="User" relatedToType="Campaign">
<messaging:htmlEmailBody > 
     <html>
        <body>
         <STYLE type="text/css">
               TH {font-size: 14px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center }
               TD  {font-size: 14px; font-face: verdana }
               TABLE {border: solid #CCCCCC; border-width: 1}
               TR {border: solid #CCCCCC; border-width: 1}
         </STYLE>
                  <font face="arial" size="3"></font>
        <p>Dear Jim Michelson,</p>
        <p>New marketing generated named account prospect(s) have been assigned to you and are now available for follow up. In addition, attached for your use is a follow up template.</p> 
        <p>To view the prospects that have been assigned to you click on the report link below.</p>
        <apex:outputLink value="https://qlogic--sandbox.cs7.my.salesforce.com/00OM0000000h74W">Named Account Prospects Eastern Region </apex:outputLink><br></br>

<table border="1"></table>
<tr></tr>
<table border="0" >
                 <tr >
                     <th>Prospect First Name</th><th>Prospect Last Name</th><th> Title </th><th> Phone </th><th> Email </th><th> State </th><th> Country </th><th>Company Name</th><th> Marketing Source</th>
                 </tr>
    <apex:repeat var="cm" value="{!relatedTo.CampaignMembers}," Rendered="{!IF(NOT(ISBLANK(!relatedTo.CampaignMembers[0].Notification_Needed__c)),true, false)}">
     <tr>
           <td>{!IF(cm.contact.id != null,cm.contact.FirstName,cm.lead.firstname)}</td>
           <td>{!IF(cm.contact.id != null,cm.contact.LastName,cm.lead.lastname)}</td>
           <td>{!IF(cm.contact.id != null,cm.contact.Title,cm.lead.Title)}</td>
           <td>{!IF(cm.contact.id != null,cm.contact.Phone,cm.lead.Phone)}</td>
           <td>{!IF(cm.contact.id != null,cm.contact.Email,cm.lead.Email)}</td>
           <td>{!IF(cm.contact.id !!= null,cm.contact.MailingState,cm.lead.State)}</td>
           <td>{!IF(cm.contact.id != null,cm.contact.MailingCountry,cm.lead.Country)}</td>
           <td>{!IF(cm.contact.id != null,cm.contact.Account.Name,cm.lead.Company)}</td>
           <td>{!cm.Campaign.Name}</td>
           </tr>
    </apex:repeat>                     
       </table>
       <p>Sincerely,</p> 
       <p>System Administrator</p>
        </body>
    </html>
</messaging:htmlEmailBody>
</messaging:emailTemplate>