Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

  • Handlebars merge format works in Custom Email Templates

  • Classic Merge Format works in Quick Text used in Lightning Emails.

  • Quick Text is good. Just use Quick Text.

  • Validated From is an Email Address and is either

    • Org Wide Default Email address

    • Email-to-Case Email address - but see Email To Case as to why you don’t want to use that.

    • The User Email

  • To can be an ID or an Email Address.

...

  • You have to create an Email button yourself the standard Email action just does not work in Cases. See Help Article.

  • Even following the help article, the Email button on its own will NOT override the From or the To or the Subject. Cases thinks it knows best and just does what it thinks is best. This is NOT best.

  • Use the JUNCTIONIDLIST formula to try to set the TO in the Email Quick Action. Eg JUNCTIONIDLIST(Case.ContactId)

  • You can only use Custom Email Templates, not even VF Email Templates or Lightning Email Templates as the default Email Template from the Button, but if you use Code, you can use Lightning Email Templates at least!

  • When you create Email Quick Actions and add them to the Case Feed, they also get added to two places on the Case Feed that is completely inappropriate!

    • The only way around this would be to have some way of making the code work for ALL scenarios from the one button. And I just can’t work out a way that can work.

    • OMG this is by DESIGN! (or at least it is documented that this will happen! UNBELIEVABLE! From the Help Doc “For each email in the case feed, agents see a dropdown menu with reply options. If you have multiple email actions in the case feed publisher, agents see groups of reply actions in the dropdown menu”. So they actually do NOT want you to EVER send a brand new email, they are only ever Replys? Sure, but then why do the Reply Actions appear in the Forward menu? Stupid. Stupid Stupid.

...

Using Code to Send Emails

My Decision Tree

Name

When

Button Name

From Address

To Address

Signature

Template

Subject

Include Body

REF Included

Attachments

To Client

Any time

Email to Client

test@example.com

Primary Contact.Email

Sender.Title

BLANK

Your Case - {subject} {EmailThreadId}

No

Yes

Add any required

Reply to existing email

Any time

Reply or Reply All from Email

test@example.com

From Address

Sender.Title

BLANK

Re: Existing Subject

Yes

Yes

No

Reply

test@example.com

From Address

Sender.Title

BLANK

Re: Existing Subject

Yes

Yes

No

Forward an existing email

Any time

Forward from Email

test@example.com

Enter a valid address

Sender.Title

BLANK

FW: Existing Subject

Yes

Yes

Included

To Third Party

Any time

Third Party Email

test@example.com

ThirdParty.Email

Sender.Title

THIRD PARTY BLANK

Case for {ClientName} - {Subject} {EmailThreadId}

No

Yes

Add any required

Code Gotchas

  • Make sure you set the setting “Enable Default Email Templates or the Default Handler for Email Action” in Support Settings and choose the Apex Class there.

  • When inserting Email Templates via Code, they can NOT include Attachments, but you can use the public link to the File in a Hyperlink on the Email, and that is a better way to send attachments anyway.

  • The ID of the Email Template for Lightning Email Templates is just the ID in the URL, but if you want to use the Developer Name you will have to use SOQL or Salesforce Inspector to see the Developer Name.

  • When you do code, ensure you cater for the standard Reply, Reply All and Forward scenarios on the Enhanced Email also.

...

Warning

Bottom Line - NEVER USE MORE THAN ONE Email Button on Cases! EVER!

Testing This Code

I am SOO stuck on testing this code.

This is the extent of the Code Coverage I am getting following many of the examples of test classes found on Github. THIS SHOULD NOT BE THIS HARD. I am trying to install this solution in an org that has only this code and I can not get anywhere near the 75% code coverage.

...

The "suggested" way to test is https://salesforce.stackexchange.com/questions/102338/test-class-for-quickaction-quickactiondefaultshandler
My test Class currently creates a Closed Case and does a Reply Email and the code coverage is not even looking at the Status of the Case let alone hitting the bit of code that actually sets the default templates.