Here is a scenario , I am stuck in. //edited post to elaborate more details.
Requirement: I need to email bulk of selected contacts. When there is no email to selected contacts, we are required to populate the name of contacts on UI who do not have the email. I am able to accomplish first part of requirement but stuck on displaying contact names on visual force page .
List button : BulkEmailTest which calls firstVF visual force page.
firstVF code:
<apex:page standardController="Contact" extensions="FirstController" recordSetVar="listRecs" action="{!send}"> Emails are being sent! window.history.back(); </apex:page>
FirstController code: for simplified code, I have edited snippet for contacts with email as our priority is only related to contacts with no email.
public with sharing class FirstController { public List noEmail {get;set;} public Contact contact; public List 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(); set ids = new set();
for(Integer i=0;i<setCon.getSelected().size();i++){ ids.add(setCon.getSelected()[i].id); } if(ids.size() == 0){ err = true; return null; }
List 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 visual force page code
<apex:page controller="FirstController"> Emails are not sent to below contacts :
Name<apex:repeat var="cx" value="{!allcontact}" rendered="true">
{!cx.name}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.
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.
.