Send email-alerts and log the email.

Use process build, flow or apex to send an email

See the sent email in the activity feed

#1 Install

  • Upvote the idea for Salesforce to make this standard.
  • Install the package – this only works on Enterprise edition and up as it requires apex code. Or view in GitHub.
  • Open a process builder (or flow)
  • On the actions select the “Apex Class” option

#2 Select the recipients

  • Related To ID – the ID of the record you want to relate this to (eg. account or opportunity). Not a contact, lead or user
  • Contact/Lead ID – Required if you use an email template
  • ‘To – To Addresses’– enter a comma-separated list of email address. Eg. [email protected], [email protected]
  • ‘To – bcc Email Addresses’– comma-separated list of email addresses to go into the BCC field
  • ‘To – cc Email Addresses’ – comma-separated list of email addresses to go into the CC field

#3 Enter the email content

  • ‘Body – Template Id’  – the id of the email template. eg. 00X600000012maf
  • Or instead, use ‘Body – Template Unique Name’ with the unique name (API name) of the email template. eg. “Email_template_name”

Or write your own content. You cannot use custom content with an email template due to a limitation in Salesforce Apex:

  • Subject – specify the subject
  • ‘Body – Plain Text ‘ – enter a plain text body
  • ‘Body – Html’ – or an HTML body
  • ‘Body – Use Signature’ – include the user’s standard signature

#4 Attachements

  • ‘Attachment – ContentDocument – Comma Separated Ids’ — This is the ContentDocumentId of the document you want to attach. It will take the latest ContentVerion.
  • ‘Attachment – ContentVersion – Comma Seperated Ids’ to specify a specific ContentVersionId
  • ‘Attachment – Comma Separated Ids’ – List of Attachment Ids

#5 Optional Extras

  • ‘From – Org Wide Email Address’ – Specify a specific from address. This must be an org wide email address.
  • ‘Setting – Save As Activity’ – You decide if you want to log the email as an activity or not. Defaults to True
  • ‘Setting – Apex Error Email’ – Send an email to the specified address containing all errors
  • ‘Setting – email Opt Out Policy’- this helps define what you do if a user has opted out of receiving emails

Limitations

  • You cannot use Email Templates without a lead or contact Id. This is a limitation of Salesforce Apex code. One workaround is to create a dummy contact. We know this is not ideal
  • Apex email sends have a limit of 5000 per day across your org. Note that all recipients in the to, cc and bcc fields count against this limit  An example being an email with 2 addresses in the “to” field and 1 address in the “cc” field would count as 3 calls against the limit.

Demo

38 Replies to “Send email-alerts and log the email.”

  1. Konstantin says:

    Hey guys! Thanks for the app! Looks pretty straight forward, I’ve set it up in one of the process builders, the email gets sent, but so far i was not able to attach the activity to neither Lead, Account or Contact, regardless whether i set the relatedTo dynamically or hardcode the value. Any thoughts what might be causing this?

    1. GravityLab says:

      Hi Konstantin,
      I’m glad the tool is going to help. Remember that any records for people (Contact/Lead/User) should not go in the relatedTo field. They should be in Contact/Lead/User Id field. You can add the Account to the relatedTo Field.
      Email a screenshot of your process builder to [email protected] and I’ll have look to make sure the tool is working as expected.

  2. CS says:

    Does this support/work with Lightning Email templates?

    1. GravityLab says:

      Great question. Yes it does!
      It’s harder to find the ID of lightning email templates. If you know how to run a SOQL query you can use “Select UiType, Name, Id, DeveloperName From EmailTemplate”.
      We will update the next version to search on names as the “Unique” or API/Developer name of email templates are different for lighnting. So it will now match on names as well.

  3. Tanja says:

    Hi,

    Can I use Field Reference to define value for Related to ID field?

    Thanks!

  4. Gary Shar says:

    Hi,

    When I am attaching the email template Classic or Lightning Email Template

    The email body that is being sent and logged is showing Text Body with HTML with tags and only the signature.

    Its not using the template.

    1. GravityLab says:

      You cannot mix a custom subject with an email template. That is probably the issue.

  5. DSS says:

    This is wonderful! Can this be used with Workflow Rules?

    1. GravityLab says:

      You can only launch invokable Apex from process builder, flows (or other code). It will not work with Workflow Rules.

  6. Anna says:

    Is there any option to dynamically add attachments? We have a custom object record which is conected via lookp up relation with a contact record and we would like to attach a file which is uploaded under files on this custom object to an email which should be sent to this related contact…

    1. GravityLab says:

      Yes. You can add files/attachments if you specify their id. You will need to create a flow to find the content or content version id and then you can include it in the email.

  7. Brad Snow says:

    Thank you for making this available!

    I get the following error when trying to use the Email Template ID:

    Error element myRule_25_A2 (FlowActionCall).
    An Apex error occurred: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []

    I went ahead and used the Email Template Unique Name and it worked, except it shows not tracked on the activity. This is tracked when using in a sandbox where I was able to use the id just fine.

    Thoughts/Suggestions….?

    Thank you

    1. GravityLab says:

      Hi Brad,

      My first assumption is that the email ID is correct. They can be different from sandbox to production. That’s why we added in the template unique name feature.

      Using the template unique name just finds the email template Id for you. It does not disable logging activity at all.

  8. Jim O says:

    Thank you for this sorely needed functionality.

    Any chance we can get this to work with Cases?

    1. GravityLab says:

      I don’t see why it wouldn’t work with cases. Have you tried it?

      1. Jim O says:

        It works – I’m an idiot.

        Thank you for putting this together – this is a huge help!

        Jim

  9. Chip T. says:

    Is there any way to change the From address? Sometimes we’d like to have the From be a generic distro list into of the User’s email.

    Thank you!

    1. GravityLab says:

      You need to set up an organisation wide email address and then set that field.
      https://help.salesforce.com/articleView?id=orgwide_email.htm&type=0

  10. Jane I says:

    Thanks so much for sharing this! I followed the instructions and got it working perfectly. I used this in a NonProfit edition org (which is an Enterprise Edition) and deactivated the NPSP Email Acknowledgement Workflow and replaced it with this.

    Worked like a charm!

  11. stephanie w. says:

    We setTreatTargetObjectasRecipient as False and target object still received email. What would cause that?

    1. GravityLab says:

      Can you try and use the updated version here:
      https://login.salesforce.com/packaging/installPackage.apexp?p0=04t0o000002o2m1

      I have created the input again and I tested it and it works now.

  12. Andi M says:

    Is there any way to use this just to log existing emails automations sent without having to recreate them all inside process builder or flow? If so I’d love a newbie demo of how to grab this info.

    1. GravityLab says:

      You will need to recreate them. You shouldn’t be using workflow rules anymore either as they are being phased out.

  13. Christa Koppijn says:

    Hi,

    I’m very excited about this app. But somehow when i use a classic e-mailtemplate with merge fields. The merge fields are not filled in the sended email or logged activity.
    Any suggestions how to correct this?

    1. GravityLab says:

      Make sure you add in the object the email template is related to so it can find the merge values.

  14. Sujay says:

    Hi,

    Thank you for the solution.
    Do you know how i can use thr app if i have a visualforce email template with attachment?

    Cheers

    1. GravityLab says:

      It works the same way. Make sure you follow the instructions carefully if you are not seeing the email work correctly.

      A common mistake is specifying a subject and an email template Id. Salesforce doesn’t allow you to do both

  15. First of all, this is UNBELIEVABLY GREAT. Thank you so so so much for making this available! The fact that it works with the native email tracking too is awesome.

    Second, it seems it won’t pull in Lightning Email Template attachments, so I tried using the Content Version ID, but must have that part wrong as I keep getting an Unhandled Fault error now. Do you have any tips for getting attachments sent? We’re trying to use a field with the attachment content version ID and reference it, just like the email template id can be referenced. Thanks again!

    1. GravityLab says:

      Hmm… It might be something to do with how Apex works with the newer lightning emails. I would first confirm that you are using ‘files’ which are stored in the database as content. How do you find the content version id?

      Secondly if that falls I would create a classic email template and just get it working 🙂

      1. Andrew says:

        I added a formula field on the Content Version record to display the Content Version ID. I grabbed it there. However, I tried it with a classic email that had an attachment and it worked flawlessly. I can’t even tell you how amazing this tool is. Best add on I’ve used maybe ever in SF for the value it delivers. THANK YOU!!

      2. GravityLab says:

        Great. You don’t need to create a formula though you can pass it a “Attachment – ContentDocument” and it automatically finds the latest content version for you.

  16. Lukas says:

    Hi,

    that’s a cool piece of software!

    When using an email template, the merge fields are empty. When I use a regular email alert in the same process the fields are filled.

    What can be the problem here?

    Br,

    Lukas

    1. GravityLab says:

      Please triple check you have followed all of the instructions. Salesforce is a bit fussy at times.

      Check you have a related to id and make sure your don’t specify a subject or body and an email template.

  17. Anusree says:

    Resolved the issue using OrgWideEmailAddress

Leave a Reply