6

When clicking on a contact's email address in the compact layout and the standard contact page a little popup for filling out an email appears. Is there a way to replicate this behavior in LWC? I've tried mailto links but that hasn't worked.

Contact page email link

1 Answer 1

1

Although it's very late to answer this question but still could be useful to anyone . You can use <lightning:quickActionAPI /> from aura components.

This api enables to use and control standard quick actions like send email through code.I have linked the original salesforce doc for the reference . https://developer.salesforce.com/docs/component-library/bundle/lightning:quickActionAPI/documentation Here is the demo code which worked for me below : Html controller :

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <lightning:quickActionAPI aura:id="quickActionAPI"/>
    <aura:attribute name="recordId" type="String" />

    <c:transactionsLWC aura:id="transactionsLWC" oncallparentmethod="{!c.openEmailPopup}" recordId="{!v.recordId}"/>
</aura:component>

JS controller :

openEmailPopup : function (component, event, helper) {
        var ToAddress = event.getParam('ToAddress');
        var CcAddress = event.getParam('CcAddress');
        var BccAddress = event.getParam('BccAddress');
        var Subject = event.getParam('Subject');
        var HtmlBody = event.getParam('HtmlBody');
        var ContentDocumentIds = event.getParam('ContentDocumentIds');
        console.log('ToAddress=='+ToAddress);
        console.log('CcAddress=='+CcAddress);
        console.log('BccAddress=='+BccAddress);
        console.log('Subject=='+Subject);
        console.log('HtmlBody=='+HtmlBody);
        console.log('ContentDocumentIds=='+ContentDocumentIds);
         
    
        var actionAPI = component.find("quickActionAPI");
        console.log('actionAPI=='+actionAPI);
        var fields;
        console.log('Here 2');
        fields = {
            HtmlBody: {
                value: HtmlBody
            }, 
            Subject: {
                value: Subject
            }, 
            ToAddress: {
                value: ToAddress
            }, 
            CcAddress: {
                value: CcAddress
            }, 
            BccAddress: {
                value: BccAddress
            }, 
            // ValidatedFromAddress: {
               // value: payload.fromId
            // },
            ContentDocumentIds:{
                value: ContentDocumentIds
            }
        };
        var args = {
            actionName: "SendEmail", 
            targetFields: fields
        };
        console.log('actionAPI', actionAPI);
        actionAPI.setActionFieldValues(args).then(function(){
            console.log('actionAPI', actionAPI);
            actionAPI.selectAction(args);
            console.log('actionAPI', actionAPI);
            //component.set('v.isOpen', false);
            //$A.util.addClass(component.find('spinner'), 'slds-hide');
        }).catch(function(e){
            console.error('error=='+e.errors);
        });
    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .