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:selectList>
</apex:pageBlockSection>

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

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

    <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}"/>
       
       
    </apex:pageBlockButtons>
    
    </apex:pageBlock>
    

</apex:form>

</apex:page>


controller

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(acc2.id,acc2.name));
            }
        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);
        
        try
        {
        insert lc;
        }
        catch(Exception e)
        {
        ApexPages.addMessages(e);
        }
        conload();
        fname='';
        lname='';
        }
     
     public void deletecon()
     {
      Contact c1=[select id from Contact where id=:index];
      delete c1;
      conload();
     }
     
     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) 
            {
                //selectedContacts.add(cCon.con);
                System.debug(cCon.con.name + ' if ');
            }
            else
            {
                System.debug(cCon.con.name + ' 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.setToAddresses(toAddresses);
            mail.setReplyTo('huria.99.anuj@gmail.com');
            mail.setSenderDisplayName('Salesforce Support');
            mail.setSubject('New Case Created : ' + case.Id);
            mail.setBccSender(false);
            mail.setUseSignature(false);
            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...