【发布时间】:2020-12-05 18:16:23
【问题描述】:
在我目前陷入的场景中需要您的输入。以下是详细信息。感谢您的时间和所有投入。
- 目前我可以看到在控制器中检索到的值,但它们没有显示在 visualforce 页面上。
要求:我需要通过电子邮件发送大量选定的联系人。当没有给选定联系人的电子邮件时,我们需要在 UI 上填充没有电子邮件的联系人的姓名。我能够完成要求的第一部分,但坚持在视觉力量页面上显示联系人姓名。
-
列表按钮:调用firstVF视觉力页面的BulkEmailTest。
-
第一个VF代码:
<apex:page standardController="Contact" extensions="FirstController" recordSetVar="listRecs" action="{!send}"> Emails are being sent! <script> window.history.back(); </script> </apex:page> -
FirstController 代码:为了简化代码,我为有电子邮件的联系人编辑了 sn-p,因为我们的优先级仅与没有电子邮件的联系人有关。
public with sharing class FirstController { public List<Contact> noEmail {get;set;} public Contact contact; public List<Contact> allcontact {get; set;} Id test; public Contact getAllContact() { return contact; } ApexPages.StandardSetController setCon; ApexPages.StandardController setCon1; public static Boolean err{get;set;} public FirstController(ApexPages.StandardController controller) { setCon1 = controller; } public FirstController(ApexPages.StandardSetController controller) { setCon = controller; } public PageReference cancel() { return null; } public FirstController() { } public PageReference send() { noEmail = new List<Contact>(); set<id> ids = new set<id>(); for(Integer i=0;i<setCon.getSelected().size();i++){ ids.add(setCon.getSelected()[i].id); } if(ids.size() == 0){ err = true; return null; } List<Contact> allcontact = [select Email, Name, firstName , LastName from Contact where Id IN :ids]; for(Contact current : allcontact) { system.debug(current); if (current.Email!= null) { PageReference pdf = Page.pdfTest; pdf.getParameters().put('id',(String)current.id); system.debug('id is :'+current.id); pdf.setRedirect(true); return pdf; } else //No email { system.debug('in else current'+current ); noEmail.add(current); // noEmail.add(current); system.debug('in else noemail'+noEmail ); }//e } if(noEmail.size()>0 ) { PageReference pdf1 = Page.NoEmailVF; pdf1.getParameters().put('Name', String.valueOf(noEmail)); system.debug('pring noEmail' +noEmail); pdf1.setRedirect(false); return pdf1; } return null; } } -
NoEmailVF 视觉力页面代码
<apex:page controller="FirstController"> <b> Emails are not sent to below contacts : <table border="1"> <tr> <th>Name</th> </tr> <apex:repeat var="cx" value="{!allcontact}" rendered="true"> <tr> <td>{!cx.name}</td> </tr> </apex:repeat> </table> <p> Please note that emails are not sent to selected Donors only when they did not make any donation for that year or if they do not have email address listed. </p> <p>If you still wish to retrieve donations made in this year, then you may use "Hard Copy" button listed on the Donor record to have the data printed. </p> </b> <apex:form > <apex:commandButton action="{!cancel}" value="Back" immediate="true"/>. </apex:form> </apex:page>
【问题讨论】: