0

My Visualforce page--

<apex:page controller="WrapperAcccountWithEachContact" sidebar="false" showHeader="false">
 <style> 
     .Processing{
         position: fixed;
         background: url('/img/loading32.gif');
         background-repeat: no-repeat;
         background-position: center;
         width: 100%;
         height: 100%;
         z-index: 10004;
         left: 0%;
         top: 0%;

     }
    </style>
  <apex:form >
  <apex:actionStatus id="status" startStyleClass="Processing"></apex:actionStatus>
  <apex:pageBlock title="Requirement Send Email on Contact from Account Seletion"  >




  <apex:pageBlockSection >
   <apex:selectList size="1" value="{!AccID}" title="data" >
       <apex:selectOptions value="{!AccountSelectList}">

       </apex:selectOptions>
       <apex:actionSupport event="onclick" status="status" reRender="dt, table" action="{!Changemethod}"/>
    </apex:selectList> 
  </apex:pageBlockSection>
  <apex:outputPanel id="dt"></apex:outputPanel>
   <apex:pageBlockTable value="{!contactList }" var="c" id="table">

                  <apex:column >                   
                    <apex:inputCheckbox value="{!c.selected}" />
                </apex:column>
                    <apex:column value="{!c.con.lastname}"/>
                    <apex:column value="{!c.con.email}"/>


    </apex:pageBlockTable>    
    <apex:commandButton value="SendMail" action="{!Changemethod}"/>

  </apex:pageBlock>
  </apex:form>

</apex:page>

My Controller class

public class WrapperAcccountWithEachContact {

public String AccID{Get;set;}
  public List<wrapper> contactList {get; set;} 
 public List<SelectOption> getAccountSelectList()
    {
        List<SelectOption> AccountSelectList =  new List<SelectOption>();
        AccountSelectList .add(new SelectOption('None','--- None ---'));        
        for(Account acc : [select id , name from Account]){
          AccountSelectList .add(new SelectOption(acc.Id,acc.name));
        }
        return AccountSelectList ;
    }

    public pageReference Changemethod()
    {
    List<Messaging.SingleEmailMessage>lstmsg = new List<Messaging.SingleEmailMessage>();
    Messaging.SingleEmailMessage objMail = new Messaging.SingleEmailMessage();
    EmailTemplate temp = [select id from EmailTemplate where name='BirthdayWish Template'];


    system.debug('AccID:::::::::;;;'+AccID);
    contactList= new list<wrapper>();
    for(contact con: [select id , lastname,email from contact where AccountID =:AccID]){
        wrapper objWrap = new wrapper(con);
        system.debug('objWrap(((((((((((((((((((((((((('+objWrap );
        contactList.add(objWrap);
        if(objWrap.selected==true){
        system.debug('objWrap!!!!!!!!!!!!!!!!!!!!!!'+objWrap);

              objMail.setTemplateId(temp.id);
              objMail.setTargetObjectId(objWrap.con.id);
              objmail.setSaveAsActivity(false);
              lstMsg.add(objMail); 
            }

    }
    if(lstMsg!=null && lstMsg.size()>0)
        {
            Messaging.sendEmail(lstMsg);
        }

       return null; 

    }

    /*public pageReference sendMail(){
         List<Messaging.SingleEmailMessage>lstmsg = new List<Messaging.SingleEmailMessage>();
         Messaging.SingleEmailMessage objMail = new Messaging.SingleEmailMessage();
         EmailTemplate temp = [select id from EmailTemplate where name='BirthdayWish Template'];
         for(WrapperClass wc:objWrap ){
            if(wc.isCheck==true){

              objMail.setTemplateId(temp.id);
              objMail.setTargetObjectId(wc.con.id);
              objmail.setSaveAsActivity(false);
              lstMsg.add(objMail); 
            }
        }
        if(lstMsg!=null && lstMsg.size()>0)
        {
            Messaging.sendEmail(lstMsg);
        }
        PageReference pr = new PageReference('/apex/ForgotPassword');
        pr.setRedirect(true);
        return pr;
    }*/

    public class wrapper{
    public Contact con {get; set;}
     public Boolean selected {get; set;}

    public wrapper(Contact c) {         
            con = c;
            selected = false;
    }
    }




}

Mail is not going.. system.debug('objWrap!!!!!!!!!!!!!!!!!!!!!!'+objWrap); this debug line not working..

0

The debug line is being skipped because your objWrap.selected is always false. That is because in your changeMethod(), you are always requerying your contacts and instantiating a new objwrap list. That wipes out any input submitted from the VF page.

What you need to do:

In your constructor, you need to retrieve the contacts and construct the list of wrapper items. The pseudocode would be something like this:

public WrapperAcccountWithEachContact() {
    List<wrapper> contactList = new List<wrapper>();
    for (Contact con : [SELECT Name, Email FROM Contact]) {
        contactList.add(new wrapper(con));
    }
}

Then in the changeMethod, you simply loop through the wrapper list and create emails for the selected contacts.

public PageReference changeMethod() {
    for (wrapper con : contactList) {
        if (con.selected) {
            // add the email here
        }
    }
}
| improve this answer | |

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.