As we all know that we can create Email Actions in Salesforce but capability to invoke Email Action from LWC components was not present. After Winter' 23, Salesforce allowed to invoke global email action from custom components (from Aura and LWC both).
In this blog, I am going to explain how to invoke email action from LWC component. You can launch email composer from custom button.
We have to use the lightning-navigation and lightning-page-reference-utils components to create a QuickAction (Global) Send Email action, which opens an email draft with pre-populated field values.
We will create simple LWC component which will have button. Once we click on this button, email composer will open. Below is sample code for reference:
<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> |
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); | |
} | |
} |
<?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> |
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>(); | |
} | |
} | |
} |
Note:
- You can default email properties like subject, body, ccAddress, toAddress and fromEmailAddress.
- You always need to provide record. Whenever you click on send button after composing email, system will create an emailmessage record with relatedToId as specified recordId.
- encodeDefaultFieldValues is being provide to specify all default values.
FRESH UPDATED 2023 QUALITY FULLZ
ReplyDeleteUSA UK CANADA RUS FR AUS
All types of Info available WITH GUARANTEE
Fresh, Legit & Verified info
*SSN DOB DL FULLZ (USA)
*SIN DOB ADDRESS (CANADA)
*CC CVV WITH BILLIING ADDRESS (USA|UK|CANADA|AUS)
*DL SCAN FRONT & BACK WITH SSN & SELFIE (USA ALL STATES)
*HIGH CREDIT SCORE FULLZ (USA|CANADA)
*FULLZ FOR PUA|UI|KYC|TAX RETURN|OPENING ACCOUNTS
*YOUNG AGE FULLZ (AGE 2002 ABOVE)
*CLONING CARDS
*FULLZ FOR DOORDASH|UBEREATS|APPLYING LOANS
*CARDING METHODS|LOAN METHODS
*SPAMMING & HACKING TOOLS & TUTORIALS
*OFFICE365 LEADS & LOGINS
*BULK FULLZ AVAILABLE (USA|CANADA|UK)
ICQ 752822040 | @killhacks
Telegram @leadsupplier | @killhacks
Email hacksp007 @ DNMX.org
Skype|Wickr @peeterhacks
FEEL FREE TO CONTACT
NO SAMPLING FOR CC's
Payment Mode BTC|USDT|ETH or any crypto
We cook and deliver simple and tasty food using traditional Indian recipes and high-quality ingredients only. Everything is made from scratch every day by our incredibly skilled Indian chefs in their own home kitchens- No powders, No Paste, No Nonsense.
ReplyDeleteTiffin service near me
GENUINE, FRESH & VERIFIED STUFF AVAILABLE
ReplyDeleteUSA UK CANADA FR RUS ITALY
FRESH SPAMMED NOV-2023
USA REAL DL SCAN FRONT BACK WITH SELFIE
SSN DOB DL FULLZ
DEAD FULLZ
SIN DOB FULLZ CANADA
BUSINESS EIN COMPANY FULLZ
YOUNG AGE FULLZ
FULLZ FOR SBA|PUA|UI|KYC|UBER|DOORDASH
CC WITH CVV & BILLING ADDRESS
DUMPS WITH PIN TRACK 101 & 202
TOOLS & TUTORIALS AVAILABLE AS WELL
SMTP|RDP|C-PANEL|WEB-MAILER
BRUTES|SHELLS|AWS-MAILER
OFFICE365 SMTP|LEADS|LOGINS
CONTACT FOR ORDER & MORE INFO
EMAIL = bigbull0334 @ onion mail. org
ICQ = 752822040 | @killhacks
TELEGRAM = @killhacks | @leadsupplier
SKYPE|WICKR = @peeterhacks
What a wonderful blog it really helped me to understand new things and contains some interesting topics so keep writing this amazing stuff also have a look at this ICSI Treatment Centre in Delhi
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThe Endgame: Quality Over Quantity
ReplyDeleteAt the heart of the YouTube community lies a simple, albeit challenging, truth: quality always trumps quantity. Whether it's the authenticity of your story or the caliber of your production, what truly captivates and retains viewers is content that offers value beyond a superficial click. This value is the currency of the platform; it's what endears subscribers, promotes sharing, and ultimately propels your videos up the view hierarchy.
https://www.buyyoutubesubscribers.in/youtube-video-views/
Best Site to Buy CC - Dumps - CVV fullz - Dumps pin - Software - Bank Login with login Info
ReplyDelete----------------
Spamming tools Like;
cPanel hosting
WHM
Windows RDP
Inbox SMTP
SMS Leads Phone Numbers.
Email Leads.
Office 365 Email Leads.
Bulk Phone Numbers.
Residential Proxies.
Email Extractor.
Bank Logs Of All Countries.
Fullz Debit/Credit Cards.
Bill-Payments and Other Payments
Money transfer.
And more spamming tools are available here.
-----------------
Contact Me at Tele-gram: @cpanelmaster
I.C.Q: @cpanelmaster
Our site: https://toolz.store
this is a useful blog it really helped me to understand new things and contains.keep writing just like as useful content. I apperciate your knowledge and intelligence.
ReplyDelete