Visualforce Page:

<apex:page controller=”relatedcontacts”>
function showModal(val){
<apex:form >
<apex:pageblock >
<apex:pageBlockSection title=”Records”>
<apex:pageBlockTable value=”{!Accounts}” var=”a”>
<apex:column headerValue=”Name”>
<apex:commandlink value=”{!a.Name}” onclick=”showModal(‘{!a.accid}’)” />
<apex:column headerValue=”phone” >
<apex:column headerValue=”website” >
<apex:column headerValue=”taxable” >

public with sharing class relatedcontacts {
public relatedcontacts(){
list<Account> lstacc = new list<Account>();
list<accountwrapclass> lstAccwrap = new list<accountwrapclass>();
public list<accountwrapclass> getAccounts() {
// lstacc=[select id,name,phone,website,taxable__c from Account];
return lstAccwrap ;
public void AccountData(){
for(Account acc:[select id,name,phone,website,taxable__c from Account]){
accountwrapclass objacc = new accountwrapclass();
objacc.Name = acc.Name;
objacc.accid =; =; =;
if(acc.taxable__C == true){
objacc.taxable =’yes’;
objacc.taxable =’NO’;

wrapper class :
public class accountwrapclass{
public string accid{get;set;}
public string Name{get;set;}
public string Phone{get;set;}
public string Website{get;set;}
public string taxable{get;set;}
contacts with checkbox:second page
<apex:page controller=”wrapperClassController” showHeader=”false” >
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location=”bottom”>
<apex:commandButton value=”Send Email” action=”{!processSelected}” rerender=”table” />
<!– In our table we are displaying the cContact records –>
<apex:pageBlockTable value=”{!contacts}” var=”c” id=”table”>
<apex:column >
<!– This is our selected Boolean property in our wrapper class –>
<apex:inputCheckbox value=”{!c.selected}”/>
<!– This is how we access the contact values within our cContact container/wrapper –>
<apex:column value=”{!c.con.Name}” />
<apex:column value=”{!c.con.Email}” />
<apex:column value=”{!c.con.Phone}” />


public class wrapperClassController {
public string accid ;
public wrapperClassController (){
accid = apexpages.currentpage().getparameters().get(‘id’);
//Our collection of the class/wrapper objects cContact
public List<cContact> contactList {get; set;}
//This method uses a simple SOQL query to return a List of Contacts
public List<cContact> getContacts() {
if(contactList == null) {
contactList = new List<cContact>();
for(Contact c : [select Id, Name, Email, Phone from Contact where AccountId=:accid]) {
// As each contact is processed we create a new cContact object and add it to the contactList
contactList.add(new cContact(c));
return contactList;
public PageReference processSelected() {
//We create a new list of Contacts that we be populated only with Contacts if they are selected
List<Contact> selectedContacts = new List<Contact>();
//We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
for(cContact cCon : getContacts()) {
if(cCon.selected == true) {
// Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
System.debug(‘These are the selected Contacts…’);
for(Contact con : selectedContacts) {
string conEmail = con.Email;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {conEmail};
//String[] ccAddresses = new String[] {‘’};
// Assign the addresses for the To and CC lists to the mail object.
// mail.setCcAddresses(ccAddresses);
// Specify the address used when the recipients reply to the email.
// Specify the name used as the display name.
mail.setSenderDisplayName(‘Salesforce Support’);
// Specify the subject line for your email address.
mail.setSubject(‘New Case Created : ‘ + case.Id);
// Set to True if you want to BCC yourself on the email.
// Optionally append the email signature to the email.
// The email address of the user executing the Apex Code will be used.
// Specify the text content of the email.
mail.setPlainTextBody(‘Thank for Contacting’);
mail.setHtmlBody(‘Thank for Contacting’);
// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
// system.debug(con);
return null;
// This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
public class cContact {
public Contact con {get; set;}
public Boolean selected {get; set;}
//This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
public cContact(Contact c) {
con = c;
selected = false;