function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anuj huriaanuj huria 

wrapper class to send emails using checkbox

apex page

<apex:page controller="accToPick">
<apex:form >
<apex:pageBlock title="Accounts">
<apex:pageBlockSection >

<apex:selectList size="1" multiselect="false" value="{!val}">

<apex:selectOptions value="{!accounnames}"/>
<apex:actionSupport event="onchange" action="{!conload}" reRender="conlist" />

<apex:pageBlockTable id="conlist"  var="a" value="{!ist}">
<apex:column value="{!}"/>
<apex:Column headerValue="action" > 
<apex:commandLink value="delete" action="{!deletecon}" reRender="conlist">
<apex:param name="index" value="{!}" assignTo="{!index}"/>
<apex:column value="{!}"/>>
<apex:column headerValue="send Email to">
<apex:inputCheckbox value="{!selected}"/>

<apex:commandButton value="send Mail" action="{!sendmail}"/>

    <apex:pageBlock >
    <apex:outputLabel >First Name</apex:outputLabel>
    <apex:inputText value="{!fname}" />
    <apex:outputLabel >Last name</apex:outputLabel>
    <apex:inputText value="{!lname}"/>
    <apex:pageBlockButtons >
    <apex:commandButton value="add Contacts" action="{!addContact}"/>




public class accToPick 


List<Account> acc;
public String val{get;set;}
 public List<Contact> ist{get;set;}
  public String index {get;set;}
  public Boolean selected {get; set;}
  public String fname{get;set;}
  public String lname{get;set;}

    public accToPick()
    acc= [SELECT id,name FROM Account];
    public List<SelectOption> getAccounnames() 
        List<SelectOption> accOptions= new List<SelectOption>();
        for(Account acc2:acc)
            accOptions.add(new selectOption(,;
        return accOptions;

    public List<Contact> conload()
          ist= [SELECT id,name,email from Contact where Account.Id=:val];
         return null;
    public void addContact()
        Contact lc=new Contact(FirstName=fname,LastName=lname,AccountId=val);
        insert lc;
        catch(Exception e)
     public void deletecon()
      Contact c1=[select id from Contact where id=:index];
      delete c1;
     public PageReference sendmail()
         List<cContact> contactList = new List<cContact>();
            for(Contact c : [select Id, Name, Email, Phone from Contact where AccountId =:val])
                contactList.add(new cContact(c));
         List<Contact> selectedContacts = new List<Contact>();
        for(cContact cCon :contactList) 
        {System.debug(cCon.selected + ' if ');
            if(cCon.selected == true) 
                System.debug( + ' if ');
                System.debug( + ' else ');
        /*System.debug('These are the selected Contacts…');
        for(Contact con : selectedContacts) 
            string conEmail = con.Email;
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {conEmail};
            mail.setSenderDisplayName('Salesforce Support');
            mail.setSubject('New Case Created : ' + case.Id);
            mail.setPlainTextBody('Thank for Contacting');
            mail.setHtmlBody('Thank for Contacting');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        return null;
      public class cContact 
        public Contact con {get; set;}
        public Boolean selected {get; set;}
        public cContact(Contact c)
            con = c;
            selected = false;

anuj huriaanuj huria
if block of send mail function is not working...