0
votes

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 .

  1. List button : BulkEmailTest which calls firstVF visual force page.

  2. firstVF code:

<apex:page standardController="Contact" extensions="FirstController" recordSetVar="listRecs" action="{!send}"> Emails are being sent! window.history.back(); </apex:page>

  1. 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;

    }
    }

  2. 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.

    .
1
It looks like you want this list to populate with values after your operation. Did you set a refresh value somewhere? The page will not react to your changes unless you tell it toAbraham Labkovsky
Hi, Thanks for your response.Here is the snippet of my attempt to refresh the page (added oncomplete parameter to reload). I am still unable to get the records displayed. Please correct me if I am wrong. <apex:form > <apex:pageBlock > <apex:commandButton value="records" oncomplete="window.location.reload();"/> <apex:pageBlockTable value="{!allcontact}" var="stu"> <apex:column value="{!stu.name}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:form>srikkanth007
I also used below code <script> parent.window.opener.location.reload(); parent.window.close(); </script>srikkanth007
Please add the code to the original post and put all relevant code thereAbraham Labkovsky
i updated the code with onCompleteParameter and also the script.srikkanth007

1 Answers

0
votes

It doesn't look like your apex:commandButton has any action. If it doesn't have an action prop, no contact is being made with your Apex code. So no oncomplete should fire.

Also, when you want to refresh some data after completing some Apex call, you can use reRender prop. Put your dynamic data in an apex:outputPanel (docs), give the apex:outputPanel an id and pass that id to the reRender of your button.

See apex:commandButton docs