Created
August 20, 2023 08:14
-
-
Save Sunil02kumar/e1ecb0bb13f5a5b64f6f3798a70e4047 to your computer and use it in GitHub Desktop.
Open Standard Email composer from LWC Component - Global Email Quick Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<lightning-card title="Launch Standard Email Composer in LWC"> | |
<div style="background-color:#E6E6FA;border-style: solid;height:200px;margin:5%;padding:2%;"> | |
<lightning-button variant="neutral" label="Send an Email" onclick={onButtonClick}></lightning-button> | |
</div> | |
</lightning-card> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { LightningElement , api, track} from 'lwc'; | |
import { NavigationMixin } from 'lightning/navigation'; | |
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils'; | |
import findEmailInfo from '@salesforce/apex/skStandardEmailComposerController.findEmailInfo'; | |
export default class SkStandardEmailComposer extends NavigationMixin(LightningElement) { | |
@api emailInfo; | |
@api error; | |
connectedCallback(){ | |
this.findEmailInformation(); | |
} | |
findEmailInformation(){ | |
findEmailInfo() | |
.then((result) => { | |
this.emailInfo = result; | |
console.log('***email details-'+JSON.stringify(this.emailInfo)); | |
}) | |
.catch((error) => { | |
this.error = error; | |
}); | |
} | |
onButtonClick(){ | |
console.log('***onButtonClick-recordRelatedToId:'+this.emailInfo.recordRelatedToId); | |
var pageRef = { | |
type: "standard__quickAction", | |
attributes: { | |
apiName: "Global.SendEmail" | |
}, | |
state: { | |
recordId: this.emailInfo.recordRelatedToId, | |
defaultFieldValues: | |
encodeDefaultFieldValues({ | |
HtmlBody : "Pre-populated text for the email body.", | |
Subject : "Pre-populated Subject of the Email", | |
CcAddress : this.emailInfo.ccAddress.join(','), | |
ToAddress : this.emailInfo.toAddress.join(','), | |
ValidatedFromAddress : this.emailInfo.fromAddress, | |
}) | |
} | |
}; | |
this[NavigationMixin.Navigate](pageRef); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | |
<apiVersion>58.0</apiVersion> | |
<isExposed>true</isExposed> | |
<targets> | |
<target>lightning__AppPage</target> | |
</targets> | |
</LightningComponentBundle> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class skStandardEmailComposerController { | |
@AuraEnabled | |
public static emailWrapper findEmailInfo(){ | |
emailWrapper returnValue= new emailWrapper(); | |
//you can implement your own logic to | |
returnValue.ccAddress.add('sk111111demo@gmail.com'); | |
returnValue.ccAddress.add('sk22222demo@gmail.com'); | |
returnValue.toAddress.add('skemailtocaseEmail1@gmail.com'); | |
returnValue.fromAddress='skcurrentUser@gmail.com';//make sure it is some user address or org wide address | |
returnValue.recordRelatedToId=[select id from Account Limit 1].Id; | |
return returnValue; | |
} | |
//in wrapper you can define define ccAddress,toAddress,from address, emailBody,EmailSubject | |
public class emailWrapper{ | |
@auraEnabled | |
public string recordRelatedToId; | |
@AuraEnabled | |
public List<string> ccAddress; | |
@AuraEnabled | |
public List<string> toAddress; | |
@AuraEnabled | |
public string fromAddress; | |
public emailWrapper(){ | |
ccAddress = new List<String>(); | |
toAddress = new List<String>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment