You need to sign in to do that
Don't have an account?
tanushree roy 6
How to Send mail to contact of associated Account through wrapper Class?
My visual force 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;
}
}
}
------------------------
Here mail is not going..
Kindly help me out for this
regards
Tanushree Roy
<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;
}
}
}
------------------------
Here mail is not going..
Kindly help me out for this
regards
Tanushree Roy
In the meantime , check Test Deliverablity in your Salesforce Org
https://help.salesforce.com/articleView?id=000212386&type=1