How to Create an Email as a Quick Action in Lightning Web Component

By | June 27, 2023

In this blog, we will guide you on creating an Email as a Quick Action in Lightning Web Component. This Quick Action will allow you to open an Email Composer with predefined values. To achieve this, we will be using a Headless Quick Action approach. Upon loading the headless quick action, the user will be redirected to the email composer.

Email as a Quick Action

Please refer to the following code for implementation:-

SendmailfromQuickActionbutton.js
import { LightningElement, api } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
export default class EmailQuickAction extends NavigationMixin(LightningElement) {
    @api recordId;
    @api invoke() {
        var pageRef = {
            type: "standard__quickAction",
            attributes: {
                apiName:"Global.SendEmail"
            },
            state: {
                recordId: this.recordId,
                defaultFieldValues:
                    encodeDefaultFieldValues({
                        HtmlBody: "Hi Sir \n Good Morming \n",
                        Subject:"Greetings"
                    })
            }
        };
        this[NavigationMixin.Navigate](pageRef);
    }
}

SendmailfromQuickActionbutton.js-meta.xml
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>56.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordAction</target>
    </targets>
    <targetConfigs>
        <targetConfig targets="lightning__RecordAction">
            <actionType>Action</actionType>
        </targetConfig>
    </targetConfigs>
</LightningComponentBundle>

Output:-

Email as a Quick Action
Send Email Quick Action
Email Activity
Email Activity
Email Received
Email Received

By following the above blog instructions, you will be able to “Create an Email as a Quick Action“. If you still have queries or any related problems, don’t hesitate to contact us at salesforce@greytrix.com. More details about the Product are available on our website and Salesforce AppExchange.

We hope you may find this blog resourceful and helpful. However, if you still have concerns and need more help, please get in touch with us at salesforce@greytrix.com.

References:

Related Posts