You need to sign in to do that
Don't have an account?
LoneStar69
Trigger to default the FROM address
Hi Friends,
I want to write a trigger that defaults the FROM address of outgoing email.
I have written the below code,shows no errors but, it doesn't seem to work.
trigger Validate_OnEmail on EmailMessage (before insert, before update)
{
Set<Id> caseIds = new Set<Id>();
for (EmailMessage newEmail : trigger.new)
{
caseIds.add(newEmail.ParentID);
}
Map<id,Case> a = new Map<id,Case>([SELECT RecordTypeId FROM Case WHERE RecordTypeId = 'XYZ' AND id IN :caseIds]);
for (EmailMessage newEmail:trigger.new)
{
if( newEmail.Incoming != true && a.containsKey(newEmail.ParentId) )
{
OrgWideEmailAddress[] oadd = [select Id from OrgWideEmailAddress where Address = 'email@sample.com'];
if ( oadd.size() > 0 ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setOrgWideEmailAddressId(oadd.get(0).Id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
}
Appreciate your help!!!
I want to write a trigger that defaults the FROM address of outgoing email.
I have written the below code,shows no errors but, it doesn't seem to work.
trigger Validate_OnEmail on EmailMessage (before insert, before update)
{
Set<Id> caseIds = new Set<Id>();
for (EmailMessage newEmail : trigger.new)
{
caseIds.add(newEmail.ParentID);
}
Map<id,Case> a = new Map<id,Case>([SELECT RecordTypeId FROM Case WHERE RecordTypeId = 'XYZ' AND id IN :caseIds]);
for (EmailMessage newEmail:trigger.new)
{
if( newEmail.Incoming != true && a.containsKey(newEmail.ParentId) )
{
OrgWideEmailAddress[] oadd = [select Id from OrgWideEmailAddress where Address = 'email@sample.com'];
if ( oadd.size() > 0 ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setOrgWideEmailAddressId(oadd.get(0).Id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
}
}
Appreciate your help!!!
All Answers
Try to follow the steps and configure the default address what you want .
Setup>EmailAdministration>Organisation Wide Address>Create A record >Default Address
Please let me know if it helps .
Thnaks
Manoj
We have multiple help desks, single case feed layout and want to default FROM address to each record type.
Wondering, is there a way that this can be accomplished?