Newer Version Available
Create an Email as a Quick Action
In a custom component, create a button to launch the email composer with pre-populated
content. To launch a record create a page with pre-populated field values, use the lightning:pageReferenceUtils and lightning:navigation components together.
These examples show you how to do this using standard actions and override actions.
Launch the QuickAction (Global) Send Email action from a custom component. Quick/Standard Actions can be called using page references and the navigation service API in any custom Aura component.
Define Navigation Services, pageReference Utils, and Action Button
Define the navigation services, the pageReference utils, and the action button in component
markup.
1<lightning:navigation aura:id="navService"/>
2<lightning:pageReferenceUtils aura:id="pageRefUtil"/>
3<div>
4 <lightning:button label="Send an " value="Global.SendEmail" onclick="{! c.openPageRefModal}"/>
5</div>Pass Attributes in pageReference to navService
Pass in the appropriate attributes in pageReference to navService.
1openPageRefModal: function (cmp, event, helper) {
2
3 var navService = cmp.find("navService");
4 var actionApiName = event.getSource().get('v.value');
5 var pageRef = {
6 type: "standard__quickAction",
7 attributes: {
8 apiName : actionApiName
9 },
10 state: {
11 recordId : '003xx000004WhEiAAK',
12 }
13 };
14
15 navService.navigate(pageRef);
16}Add Predefined Fields Info
Allow the user to pass action field data as part of the pageReference attributes with the fieldOverride payload.
This code is an example of what a pageReference request could look like:
1openPageRefModal: function (cmp, event, helper) {
2 var navService = cmp.find("navService");
3 var actionApiName = event.getSource().get('v.value');
4 var pageRef = {
5 type: "standard__quickAction",
6 attributes: {
7 apiName : actionApiName
8 },
9 state: {
10 recordId : '003xx000004WhTJAA0'
11 }
12 };
13 var defaultFieldValues = {
14 HtmlBody: "Monthly Review",
15 Subject : "Monthly Review"
16 }
17 pageRef.state.defaultFieldValues = cmp.find("pageRefUtil").encodeDefaultFieldValues(defaultFieldValues);
18
19 navService.navigate(pageRef);
20}