-2

Here the requirement is we have to create a custom quick action which will call the lwc whose functionality is to fetch the email, subject from the case object and when we click send button it should send a mail to the email id mentioned but here the send button not working so please help me fixing this issue. Controller - EmailConversationCtrl

    @AuraEnabled(cacheable=true)
    public static void sendEmailToController(String toSend, String subject){
        try{
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddresses = new String[] {toSend};
            mail.setToAddresses(toAddresses);
            mail.setSubject(subject);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }catch(Exception ex){
            throw new AuraHandledException(ex.getMessage());
        }
    }
}

javascript

import { LightningElement, api, wire, track } from 'lwc';
import ContactEmail from '@salesforce/schema/Case.ContactEmail';
import Subject from '@salesforce/schema/Case.Subject';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import sendEmailToController from '@salesforce/apex/EmailConversationCtrl.sendEmailToController';

const fields = [ContactEmail, Subject];
export default class SendEmail extends LightningElement {
    @track email='';
    @api recordId;
    

    handleChange(e) {
        this.richtext  = e.detail.value;
    }

    @wire(getRecord, {
        recordId: "$recordId",
        fields
    })
    case;

    get ContactEmail() {
        return getFieldValue(this.case.data, ContactEmail);
    }

    get Subject() {
        return getFieldValue(this.case.data, Subject);
    }

    handleClick(){
        const recordInput = { ContactEmail: this.toSend, Subject: this.subject }  //You can send parameters
        sendEmailToController(recordInput)
            .then(() => {
                //If response is ok
                // eslint-disable-next-line no-unused-vars
            }).catch(error => {
                //If there is an error on response
            })
    }
}

html

<template>
    <lightning-card title='Send Email' icon-name="custom:custom14">
      <div class="slds-box slds-box_x-small">
        
        
        <lightning-input type="email" label="To"  value={ContactEmail} required>
        </lightning-input>
        <lightning-input type="text" label="Subject" value={Subject}></lightning-input>
      </div>
  
      <div class="slds-box slds-box_x-small">
        <lightning-input-rich-text value={richtext} onchange={handleChange}></lightning-input-rich-text>
        <lightning-formatted-rich-text value={richtext}></lightning-formatted-rich-text>
      </div>
  
      <div>
        <lightning-button type="submit" label="Send" variant="brand" onclick={handleClick}> </lightning-button>
      </div>
    </lightning-card>
  </template>

here handleClick() was not working so can anybody help me fixing in this LWC

1
  • 1
    Welcome to Salesforce Stack Exchange (SFSE)! Thank you for posting the code. But please edit your question to add additional information: how it is not working (e.g., exact error text, exact results different from expected). (Please read the What topics can I ask about here? section of Help Center where, among other things, it says that a question should include, 'A specific, detailed description of the issue ("it doesn’t work" is not enough to allow the community to help).')
    – Moonpie
    Jun 22 at 10:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.