Created
December 18, 2013 03:40
-
-
Save mokamoto/8016934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SendMailFromTemplateController{ | |
public List<EMailTemplate> templateList{get;set;} | |
public SendMailFromTemplateController(ApexPages.StandardController standardController){ | |
templateList = [SELECT Name,ID FROM EMailTemplate LIMIT 200]; | |
} | |
@RemoteAction | |
public static String getContents(String templateId){ | |
EMailTemplate template = [SELECT HtmlValue,Body FROM EMailTemplate WHERE id = :templateId Limit 1].get(0); | |
return template.Body; | |
String result; | |
if(template.HtmlValue != null){ | |
result = template.htmlValue.unescapeHtml4(); | |
}else{ | |
result = template.Body; | |
} | |
return result; | |
} | |
@RemoteAction | |
public static String getSubject(String templateId){ | |
EMailTemplate template = [SELECT Subject FROM EMailTemplate WHERE id = :templateId Limit 1].get(0); | |
return template.Subject; | |
} | |
@RemoteAction | |
public static void sendEmail(String subject,String body,string address){ | |
Messaging.reserveSingleEmailCapacity(2); | |
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); | |
String[] toAddresses = new String[] {address}; | |
mail.setToAddresses(toAddresses); | |
mail.setReplyTo('[email protected]'); | |
mail.setSenderDisplayName('Salesforce Support'); | |
mail.setSubject(subject); | |
mail.setBccSender(false); | |
mail.setUseSignature(false); | |
mail.setPlainTextBody(body); | |
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment