global class EmailPublisherLoader implements QuickAction.QuickActionDefaultsHandler {
// Empty constructor
global EmailPublisherLoader() {
}
public string customLabelValue{get;set;}
// The main interface method
global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) {
QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null;
// Check if the quick action is the standard Case Feed send email action
for (Integer j = 0; j < defaults.size(); j++) {
if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults &&
defaults.get(j).getTargetSObject().getSObjectType() ==
EmailMessage.sObjectType &&
defaults.get(j).getActionName().equals('Case.Email') &&
defaults.get(j).getActionType().equals('Email')) {
sendEmailDefaults =
(QuickAction.SendEmailQuickActionDefaults)defaults.get(j);
break;
}
}
if (sendEmailDefaults != null) {
Case c = [SELECT CaseNumber FROM Case
WHERE Id=:sendEmailDefaults.getContextId()];
EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject();
// Set From address to make sure each email goes from sales@inmobi.com
emailMessage.FromAddress = getfromAddress(c.CaseNumber);
}
}
// return email address, Email Address is a from Address and this value is stored in custom label Email Address Label
private String getfromAddress(String reason) {
customLabelValue = System.Label.Email_Address_Label ;
return customLabelValue;
}
}
After creating Apex class , Go to case support settings -> choose the Class Name -> Save
Hi,
ReplyDeleteI get an error at this line:
System.Label.Email_Address_Label
Can you explain this please?
Thank you, Rudolf
Rudolf, Did you create a custom label for the class to reference? Setup>Create>Custom Labels
DeleteHi Rudolf,
ReplyDeleteYou need to create a custom label as "Email Address Label" which will store the actual value of email address, the purpose to use custom label is that if in future you want to change the default email address then you just need to change the value in the label.
Thanks,
It doesn't work. I added the class with the custom label. Where exactly should we put the class under the Support Settings?. Are your sure is there where we have to put the class?
DeleteHi,
DeleteAs suggested I have added ApexClass, Label and have setup the Apex Class in the support setting of the case, but it still doesn't work.
When i click on the 'Send an Email' button from the Email related list of the case, it defaults the email address with the logged in user.
Can you please advise.
Thanks,
Sapan
Hi,
ReplyDeleteI used this code but FromAddress is not populating correctly. It doesn't take the value I provided instead the default value of the Contact's email. I tried setting BccAddress, and that is populating correctly.
Can you help with this?
Thanks
Your blog is nice. I believe this will surely help the readers who are really in need of this vital piece of information. Thanks for sharing and kindly keep updating.
ReplyDeleteBest Spoken English Training Institute in Adyar
Spoken English Classes in Gandhi Nagar
Spoken English Classes in ECR
Spoken English Center in Porur
Spoken English in Ramapuram
Spoken English Classes in Moulivakkam
Spoken English Course near me