Thys Andries Michels
Thys Andries Michels

Reputation: 781

Visualforce email link email template

I have a list of emails in a Visualforce apex:pageBlockTable and want to make the emails likable to a specific email template as well as populate the To: field with the email I clicked, is there any way to do this?

Upvotes: 0

Views: 2152

Answers (2)

subodhbahl
subodhbahl

Reputation: 415

Answer to what I understood: Logic- You will need to pass params from your visualforce page to the controller/extension so it knows which template to be used (if there are more than one). This could be achieved via radiobuttons.

As per the sending email part is concerned, just pass the value of the column which contains emails to the apex class via getters and setters. Store these emails in an array, use the sendEmail method to send the emails to the array of the emails.

Sample Code:

//VF page: //So, if you have your emails in a pageBlockTable the code must be something like:

//Apex Class:
public class Test{
    List <Email__c> listEmail = [Select Email__c from Email__c];
    String[] toAddresses = new String[] {};
    public list<Email__c> getList() {        
        return listEmail;
    }

    public Test(){
        for(integer i =0; i < listEmail.size(); i++){
            toAddresses.add(listEmail[i].Email__c);
        } 
    }

    public void  SendEmail(){
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        //pass the address list
        mail.setToAddresses(toAddresses);
        //set the templateID
         mail.setTemplateID('');
        //set other fields (like SenderName, ReplyTo, Signature) -     http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_base.htm 
        //send the email
        mail.sendEmail();
    }
} 

Please let me know if this works for you!

Cheers

Upvotes: 1

sgoldberg
sgoldberg

Reputation: 487

Do you need to be able to edit the email before hand? If not you can use a command link call a method that sends SingleEmailMessage

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm

and set the template from there...

Upvotes: 0

Related Questions