Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Created November 4, 2016 20:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglascayers/6e32a277a945f0ab25c449a283ad4dba to your computer and use it in GitHub Desktop.
Save douglascayers/6e32a277a945f0ab25c449a283ad4dba to your computer and use it in GitHub Desktop.
Apex class to auto-default values of Email when using Case Feed Email Composer. Setup | Case | Support Settings
/**
* https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_QuickAction_QuickActionDefaultsHandler.htm
*/
public class EmailQuickActionDefaultsHandler implements QuickAction.QuickActionDefaultsHandler {
public void onInitDefaults( QuickAction.QuickActionDefaults[] actionDefaults ) {
for ( QuickAction.QuickActionDefaults actionDefault : actionDefaults ) {
System.debug( actionDefault );
if ( actionDefault instanceof QuickAction.SendEmailQuickActionDefaults ) {
if ( actionDefault.getTargetSObject().getSObjectType() == EmailMessage.sObjectType ) {
QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults) actionDefault;
EmailMessage emailMessage = (EmailMessage) sendEmailDefaults.getTargetSObject();
// TODO update values on EmailMessage or call methods on sendEmailDefaults object
ID templateId = getTemplateId( '<template_to_apply>' );
if ( String.isNotBlank( templateId ) ) {
sendEmailDefaults.setTemplateId( templateId );
sendEmailDefaults.setInsertTemplateBody( true ); // apply template above original email content
sendEmailDefaults.setIgnoreTemplateSubject( true ); // don't overwrite subject, ignore template subject
}
}
}
}
}
private ID getTemplateId( String templateName ) {
ID templateId = null;
List<EmailTemplate> templates = new List<EmailTemplate>([
SELECT
id
FROM
EmailTemplate
WHERE
developerName = :templateName
LIMIT 1
]);
if ( templates.size() > 0 ) {
templateId = templates[0].id;
} else {
System.debug( LoggingLevel.ERROR, 'Unable to locate email template using name "' + templateName + '"' );
}
return templateId;
}
}
@douglascayers
Copy link
Author

@Sathish1496
Copy link

@douglascayers

Is there any possiblity where we can get the related attachment from Email Template to also be displayed as Default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment