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
chiranthchiranth 

Email To case

When a user is sending an email from a case, the senders email address should be based on the case record type.  If the case record type is returns, then it should be returns@Test.com. If recor dtype is test then it should be test@test.com.

 

How can this be done ?? Please help me on this.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Jean-NoelJean-Noel

Yes, it's possible but you'll need to write some apex code for it.

All Answers

Jean-NoelJean-Noel

You can use Organization-Wide Email Addresses for sending emails.

chiranthchiranth

Ya i have used it . But what i need is like, Once i click on the send email button on case the from address hould me automatically poplated based on the record type selected.

If the case record type is quote then from address should be quote@test.com ,

If the case recor dtype is bill then from address should be bill@test.com,

 

Is this possible?

Jean-NoelJean-Noel

Yes, it's possible but you'll need to write some apex code for it.

This was selected as the best answer
chiranthchiranth

Can u please post any sample code ? It will be helpful.

Jean-NoelJean-Noel

Something like that should do the trick

 

c represent your case

 

EmailTemplate et = [SELECT id FROM EmailTemplate WHERE developerName = 'Your Template name depend on the recordtype'];

OrgWideEmailAddress owea = [SELECT id FROM OrgWideEmailAddress WHERE DisplayName = 'Your Org name depend on the recordtype'];

 

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

mail.setTargetObjectId(c.Contact.Id); // Specify who the email should be sent to.

mail.setTemplateId(c.id);

mail.whatId = c.Contact.Account.Id;
mail.orgWideEmailAddressId = owea.Id;

Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});