Visual force code
<apex:page controller="test_Controller" >
<apex:form >
<script language="javascript">
function hello()
{
alert('Hello here ');
}
</script>
<apex:commandButton value="Send Email" action="{!SendEmail}"/>
<apex:pageBlock title="Account Records">
<apex:pageBlockTable value="{!liRecords}" var="li">
<apex:column >
<input type="checkbox" value="{!li.check}" onchecked="{!send}"/>
</apex:column>
<apex:column value="{!li.opr.OpportunityId} " />
<apex:column value="{!li.opr.Role}" />
<apex:column value="{!li.opr.ContactId}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:form >
<script language="javascript">
function hello()
{
alert('Hello here ');
}
</script>
<apex:commandButton value="Send Email" action="{!SendEmail}"/>
<apex:pageBlock title="Account Records">
<apex:pageBlockTable value="{!liRecords}" var="li">
<apex:column >
<input type="checkbox" value="{!li.check}" onchecked="{!send}"/>
</apex:column>
<apex:column value="{!li.opr.OpportunityId}
<apex:column value="{!li.opr.Role}" />
<apex:column value="{!li.opr.ContactId}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
controllerpublic class test_Controller
{
public String send {
get;
set
{
sendcontacts.add(ApexPages. currentPage().getParameters(). get('li.contactid'));
}
}
public List <String> sendcontacts;
public PageReference SendEmail()
{
for(Record r : liRecords)
{
if(r.check==true)
{
Contact c = [Select Id, Name, Email FROM Contact where id=:r.opr.contactId];
if(c!=null)
{
if(c.email!=null)
{
Messaging. reserveSingleEmailCapacity(2);
// Processes and actions involved in the Apex transaction occur next,
// which conclude with sending a single email.
// Now create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage() ;
// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {c.email};
String[] ccAddresses = new String[] {'smith@gmail.com'};
// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses( toAddresses);
mail.setCcAddresses( ccAddresses);
// Specify the address used when the recipients reply to the email.
mail.setReplyTo('support@acme. com');
// 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.
mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);
// Specify the text content of the email.
mail.setPlainTextBody('Your Case: ' + case.Id +' has been created');
mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+
' View case <a href=https://na1.salesforce. com/'+case.Id+'>click here</a>');
// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
}
contactid=ApexPages. currentPage().getParameters(). get('li.contactid');
contacts=[Select Id, Name, Email FROM Contact where name=:contactid];
return null;
}
public List<OpportunityContactRole> oppList;
public String Oppid {get;set;}
public string contactid;
public List <Contact> contacts;
public List<record> liRecords ;
public List<record> getliRecords()
{
return lirecords;
}
public List<OpportunityContactRole> getoppList()
{
return oppList;
}
public test_Controller()
{
liRecords = new List<record>();
oppList = new list<OpportunityContactRole>() ;
oppid = ApexPages.currentPage(). getParameters().get('id');
System.debug('================ =======>>Oppid'+oppid);
oppList = [Select Id, OpportunityId, ContactId, Role FROM OpportunityContactRole where OpportunityId=:oppid];
for(OpportunityContactRole t : opplist)
{
record r = new record();
r.check = false;
r.opr = t;
liRecords.add(r);
}
System.debug('================ =======>>Oppid'+oppList );
System.debug('================ =======>>Rcords'+lirecords );
}
class record
{
public Boolean check{get;set;}
public OpportunityContactRole opr{get;set;}
}
}
{
public String send {
get;
set
{
sendcontacts.add(ApexPages.
}
}
public List <String> sendcontacts;
public PageReference SendEmail()
{
for(Record r : liRecords)
{
if(r.check==true)
{
Contact c = [Select Id, Name, Email FROM Contact where id=:r.opr.contactId];
if(c!=null)
{
if(c.email!=null)
{
Messaging.
// Processes and actions involved in the Apex transaction occur next,
// which conclude with sending a single email.
// Now create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage()
// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {c.email};
String[] ccAddresses = new String[] {'smith@gmail.com'};
// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(
mail.setCcAddresses(
// Specify the address used when the recipients reply to the email.
mail.setReplyTo('support@acme.
// Specify the name used as the display name.
mail.setSenderDisplayName('
// 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.
mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);
// Specify the text content of the email.
mail.setPlainTextBody('Your Case: ' + case.Id +' has been created');
mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+
' View case <a href=https://na1.salesforce.
// Send the email you have created.
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
}
contactid=ApexPages.
contacts=[Select Id, Name, Email FROM Contact where name=:contactid];
return null;
}
public List<OpportunityContactRole> oppList;
public String Oppid {get;set;}
public string contactid;
public List <Contact> contacts;
public List<record> liRecords ;
public List<record> getliRecords()
{
return lirecords;
}
public List<OpportunityContactRole> getoppList()
{
return oppList;
}
public test_Controller()
{
liRecords = new List<record>();
oppList = new list<OpportunityContactRole>()
oppid = ApexPages.currentPage().
System.debug('================
oppList = [Select Id, OpportunityId, ContactId, Role FROM OpportunityContactRole where OpportunityId=:oppid];
for(OpportunityContactRole t : opplist)
{
record r = new record();
r.check = false;
r.opr = t;
liRecords.add(r);
}
System.debug('================
System.debug('================
}
class record
{
public Boolean check{get;set;}
public OpportunityContactRole opr{get;set;}
}
}
No comments:
Post a Comment