0

I am creating a visualforce email template that sends contact data to salespeople.

In this email there are two points that I am not able to advance:

  1. In the section "Informações sobre o agendamento", I would like that the apex repeat that has below it to bring the start and end date information only if the subject of the event starts with "Agd:"

  2. Below in "Tarefas Relacionadas" and "Compromissos relacionados" I needed the subject of each task or event to link to those tasks, but I don't know how to bring the link to custom shape.

Could someone please help me with these questions?

Below I leave all the email code for analysis :)

<messaging:emailTemplate subject="Novo agendamento!" recipientType="Contact" relatedToType="Contact">
<messaging:htmlEmailBody > 
    <html>
        <body>
        
            <table>
               <tr>
                   <p>Olá{!relatedto.Owner.FirstName}, tudo bem?</p>
               </tr>
               <tr>
                   <p>Você tem uma nova reunião agendada!</p>
               </tr>
               <tr>
                   <p>Confira abaixo tudo o que você precisa saber sobre seu lead e o agendamento!</p>
               </tr>
             </table>
            <table>
                 <tr>
                     <th>Informações sobre o agendamento</th>
                 </tr>
                 <apex:repeat rows="1" value="{!relatedTo.Events}" var="event">
               <tr>
                   <p><strong> Início: </strong>{!event.StartDateTime}</p>
                   <p><strong> Fim: </strong>{!event.EndDateTime}</p>
               </tr>
               </apex:repeat>
               <tr>
                   <p><strong>Nome da empresa:</strong> {!relatedto.Account.Name}</p>
               </tr>
               <tr>
                   <p><strong>Site:</strong> {!relatedto.Account.Website}</p>
               </tr>
               <tr>
                   <p><strong>Telefone:</strong> {!relatedto.Phone}</p>
               </tr>
               <tr>
                   <p><strong>Nome:</strong> {!relatedto.Name}</p>
               </tr>
               <tr>
                   <p><strong>Cargo:</strong> {!relatedto.Title}</p>
               </tr>
               <tr>
                   <p><strong>E-mail:</strong> {!relatedto.Email} </p>
               </tr>
               <tr>
                   <p><strong>Setor:</strong> {!relatedto.Account.Industry}</p>
               </tr>
           </table>
           <table>
               <tr>
                   <th>Tarefas Relacionadas</th>
               </tr>
               <apex:repeat rows="5" value="{!relatedTo.Tasks}" var="tarefa">
               <tr>
                   <td>
                       <p><strong> Assunto: </strong>{!tarefa.Subject}</p>
                   </td>
               </tr>  
               </apex:repeat>
           </table>
           <table>
               <tr>
                   <th>Compromissos relacionados</th>
               </tr>
               <apex:repeat rows="5" value="{!relatedTo.Events}" var="compromisso" >
               <tr>
                   <td>
                       <p><strong> Assunto: </strong>{!compromisso.Subject}</p>
                   </td>
               </tr>  
               </apex:repeat>
           </table>
        </body>
    </html>
</messaging:htmlEmailBody> 

</messaging:emailTemplate>

1

The former is just a simple apex:outputText/rendered setup:

       <apex:repeat rows="1" value="{!relatedTo.Events}" var="event">
           <apex:outputText rendered="{!LEFT(event.Subject,4)='Agd.'}">
           <tr>
               <p><strong> Início: </strong>{!event.StartDateTime}</p>
               <p><strong> Fim: </strong>{!event.EndDateTime}</p>
           </tr>
           </apex:outputText>
       </apex:repeat>

For the latter, use an anchor tag (<a>):

           <apex:repeat rows="5" value="{!relatedTo.Tasks}" var="tarefa">
           <tr>
               <td>
                   <p><strong> Assunto: </strong>
                    <a href="{!URLFOR($Action.Task.View,tarefa.Id)}">{!tarefa.Subject}</a>
                   </p>
               </td>
           </tr>  
           </apex:repeat>
4
  • Thanks a lot for your answer! The first code helped me to bring the right event, but the second one doesn't work so well :( It gives an error because it's not linking yet to the right task. Do you know another condition that I can use? Or maybe some documentation showing all of them? – Leticia Silva Jordao Apr 12 at 16:12
  • @LeticiaSilvaJordao What's the error? – sfdcfox Apr 12 at 18:36
  • A new page opens with the following message: Redirect warning The page on which you were is trying to get you to an invalid url (http:///00T2D000008hHjOUAU/d?retURL=%2Fp%2Femail%2Ftemplate%2FVfEmailTemplatePreview%3Fsetupid%3DCommunicationTemplatesEmail%26isdtp%3Dp1&_CONFIRMATIONTOKEN=VmpFPSxNakF5TVMwd05DMHhOMVF4TURvd016bzBNeTR3T0RoYSxLc2lBNXd2LTlwb05oSjM1N3dqWE9ILE5UWXhNalZq&common.udd.actions.ActionsUtilORIG_URI=%2F00T2D000008hHjOUAU%2Fd&isdtp=p1). If you don't want to visit that page, you can go back to the previous page. – Leticia Silva Jordao Apr 14 at 10:06
  • @LeticiaSilvaJordao That's weird. It shouldn't be doing that. You'll probably need to use something like: href="{!$Site.BaseUrl}/{!tarefa.Id}" instead. – sfdcfox 2 days ago

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.