• Services
      • Managed Services
      • Strategic Services
      • Implementation
      • Optimization
      • System Expansion
      • Custom Development
      • Training
  • Technology
      • Partners
      • Salesforce
      • Pardot
      • Marketo
      • Salesforce CPQ
  • Knowledge Center
      • Clients
      • Case Studies
      • Blog
  • About
      • Leadership
      • Contact
  • Careers

For Developers

Email Author for Salesforce Lightning Experience

Veena Sundara-Heragu

If you have been doing Salesforce development for some time, you have probably run into the need to create a custom button to call the email author with certain attributes of the email populated, such as the Subject, To or Email Template. With Salesforce Classic, this was very easy to do with a custom JavaScript button and some URL hacking. If you are planning a lightning migration for a Salesforce instance that contains such custom buttons or you have a Salesforce Lightning instance where you would like to add such functionality, you will be disappointed to find out that this kind of URL hacking of the email author will not work with Salesforce lightning.

In my case, I was trying to migrate a Salesforce instance to lightning when I came across this problem and decided to create a lightning component to accomplish this.

This is what the component looks like:

The functionality of the component is very similar to the Salesforce classic email author.  Email templates can be selected, the “From” can be set to the current logged in user or any available organization wide email addresses, cc, bcc and additional to values can be entered either as email addresses or multiple contacts can be selected, etc.

The component implements lightning:isUrlAddressable so that it can be accessed from other lightning components using lightning:navigation as follows:

<!-- calling component -->
<lightning:navigation aura:id="navService"/>


// Calling component javascript helper
var navService = component.find("navService");
var pageReference = {
    "type": "standard__component",
    "attributes": {
        "componentName": "c__CmpSendEmail",
    },
    "state": { // use these to prefill values in the CmpSendEmail 
               // component, leave empty otherwise
        "to" : contactId,
        "relatedTo": "Quote",
        "relatedToRecord": quoteId,
        "templateId": emailTemplateId,
        "lstFiles": JSON.stringify(lstAttachment)
    }
};
navService.navigate(pageReference);

 

As you can see, this sample code populates some of the fields of the email author.

The complete set of values that can be populated are as follows:

templateId – id of email template to use
format – ‘Text’ or ‘HTML’
from – running user’s User Id OR organization wide email address Id
to – Contact Id
relatedTo – API name of SObject
relatedToRecord – Id of record of the relatedTo SObject
additionalTo – list if email addresses separated by semicolon (eg. ‘jack@yahoo.com;john@gmail.com’)
cc – list if email addresses separated by semicolon
bcc – list if email addresses separated by semicolon
useSignature – Boolean (true or false)
subject – String for subject of email
body – String for body of email (if a template is specified, this will be overridden with the body from the template)
lstFiles – JSON stringified list of Ids of Attachments or Content Documents

If you have reached this line, you are probably keen on seeing the code.  View the lighting code on GitHub and contact us for custom Salesforce lighting development.

This component utilizes a custom lookup component developed by us. Please check out other interesting blogs by our development team.

Please comment below to let us know how you like this component.

October 22, 2018

About the Author

Veena Sundara-Heragu

Veena is a Sr Salesforce Developer at OpFocus. Primarily focused on projects using Apex, Veena is excited about Lightning Experience, and actually dislikes coding Visualforce! (Shhhhh)

Related Posts

November 25, 2020

End of Year Operations: Dos and Don’ts

Kyle Chagnon
October 9, 2020

Meet Some of the All-Star OpFocus Development Team!

Kyle Chagnon
September 23, 2020

Integrating your SaaS Platform with Salesforce – Everything you need to know

Kyle Chagnon

Leave a Comment

Click here to cancel reply.


Sign up for weekly OpFocus blog updates!

OpFocus, Inc.

LinkedIn
Twitter
Instagram
Facebook
YouTube

Quick Links

  • Services
  • Technology
  • Case Studies
  • About
  • Careers

Office Locations

OpFocus, Inc.
200 F Main Street
#317 Stoneham, MA
02180 USA
+1 (781) 214-7440 info@opfocus.com

Canada
1 Yonge Street
Suite 1203
Toronto, ON M5E 1W7
(416) 848-0490 info@opfocus.com

  • © 2006 - 2020 OpFocus All Rights Reserved

    Privacy Policy | Terms of Use

  • We use cookies to make interactions with our website and services easy and meaningful. To better understand how they are used, you can read more about our cookie policy. By continuing to use this site you are giving us your consent to do this.