Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to resolve the error - cannot read property 'play' of undefined?

Asked by David Edmunds Mar 1, 2023 958 views 4 answers
Share

About this question

I'm getting the above error in the below code.


@api guestFirstName; //getting these from parent component
@api guestLastName;
@api guestPhoneNumber;
@api guestCodeFromGuestMaster;
@api guestEmailFromGuestMaster;
//LWC code
   sendEmailAfterEvent() {
    const recordInput = { toSend: this.guestEmailFromGuestMaster, firstName: this.guestFirstName, lastName: this.guestLastName, phoneNumber: this.guestPhoneNumber }  //send parameters
    sendEmailToController(recordInput).then(response => {
        console.log('Email has been sent...!');
    }).catch(error => {
        console.log('facing error in sending email ',error.message.body); //If there is an error on response
    })
}
//APEX controller code
public with sharing class ControllerLwcExample {
@AuraEnabled(cacheable=true)
public static void sendEmailToController(String toSend, string firstName, string lastName, Integer phoneNumber){
    try{
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {toSend};
        mail.setToAddresses(toAddresses);
        mail.setSubject('Booking Confirmation');
        String body = 'Dear ' + firstName + ', ';
        body += 'Your booking has been confirmed.';
        body += 'Please find the details below:';
        body += 'First Name: '+firstName;
        body += 'Last Name: '+lastName;
        body += 'Phone Number: '+phoneNumber;
        body += 'Regards';
        body += 'Hotel Hotel Hotel';
        mail.setHtmlBody(body);
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }catch(Exception ex){
        throw new AuraHandledException(ex.getMessage());
    }
}
}

I don't find any problem with the above code but I'm still getting the below error. Any help would be appreciated.

error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'body')

Your answer

4 Answers

Anyana Latest answer

Answered on May 19, 2026

If there are any recommended setups or tweaks that could enhance performance.

Thank you

snow rider 3d

Was this helpful?

Bevisandrew

Answered on Apr 7, 2025

It looks like the error you're encountering may be due to the way you're accessing the error message in your catch block. Instead of error.message.body, try using error.body.message to get the correct message. In my experience, debugging issues like this can be tricky, but tools like block breaker have helped me sharpen my problem-solving skills. Keep at it, and you'll get to the bottom of this!

Was this helpful?

Cleve Blick

Answered on Feb 6, 2025

scratch games online updates are really detailed for effective access and tracking. Each information function really needs absolute precision to achieve maximum program running efficiency. Unlike traditional game platforms, Scratch allows anyone to create their own games without knowing much about programming. Drag-and-drop programming tools make it easy for users to create movements, effects, and character controls.

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.