function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Austin JRBAustin JRB 

One-click Email template from Case

Our Support team would like to be able to have a button on a Case to invoke a standard email response template from that Case.  Any existing code for this?
 
Thanks
 
JRB
TehNrdTehNrd
I'm not sure of existing code but this should be pretty easy to do.

First you need the button on the Case that will call a class method:
Code:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/13.0/apex.js")}

var caseID = '{!Case.Id}';

var agree = confirm("Are you sure you wish to send this e-mail?");
if(agree){

var result = sforce.apex.execute("emailClass","sendEmail",{caseID : caseID });

alert(result);

location.reload(true);

}

}

And then the class:
Code:
lobal class emailClass{

webservice static string sendEmail(ID caseID ){

String errorMessage = 'Email successully sent';

//Query the case to get any info you need
Case c = [select, Id, email, Name, whatever from Case where Id = :caseID];

//Send the email
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setPlainTextBody();
mail.setHtmlBody(htmlBody);
mail.setToAddresses(emailAddress);
mail.setBCCsender(false);
mail.setCCAddresses(CCemailAddresses);
mail.setReplyTo(primaryContact.Email);
mail.setSenderDisplayName('Name');
mail.setSubject('Subject');
mail.setUseSignature(false);

try{
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}catch (exception e){
error = 'There was a problem processing the email. Please contact your system administrator.';
}
}

return errorMessage;


 A lot more info and details can be found in the Apex Reference gude and force.com cookbook but here is the general idea.

-Jason


Message Edited by TehNrd on 07-17-2008 01:25 PM
Austin JRBAustin JRB
Thanks, jason.  I'll try this out first chance I get.
 
JRB