Created
November 4, 2016 20:45
-
-
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
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
/** | |
* 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; | |
} | |
} |
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
For reference when needing to create unit test: http://salesforce.stackexchange.com/questions/102338/test-class-for-quickaction-quickactiondefaultshandler