I am trying to create a record in an object and on record creation I want to display the salesforce id of that particular record on the toast message. If I comment out the "message: "New School Salesforce ID: "+this.event.id," line from .js file, the toast message is coming up as expected but if I include that line trying to display the id, I face the below outcome:

enter image description here

My code is as shown below:


<lightning-card title="SCHOOL RECORD CREATION FORM">

JS ->

import { LightningElement } from 'lwc';
import SCHOOL_OBJECT from '@salesforce/schema/School__c';
import NAME_FIELD from '@salesforce/schema/School__c.Name';
import PHONE_FIELD from '@salesforce/schema/School__c.School_Phone__c';
import EMAIL_FIELD from '@salesforce/schema/School__c.School_Email__c';
import FEES_FIELD from '@salesforce/schema/School__c.Fees__c';
import ADDRESS_FIELD from '@salesforce/schema/School__c.School_Address__c';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';

export default class CreateSchoolRecord extends LightningElement {

objectApiName = SCHOOL_OBJECT;

    const evt = new ShowToastEvent({
    title: "School record has been created",
    message: "New School Salesforce ID: "+this.event.id,
    variant: "success"


XML ->

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

3 Answers 3


Are you sure your event.id represents the Salesforce ID? In any case - you want to remove "this" (because your event variable is local):

message: "New School Salesforce ID: " + event.id,

Update in answering your comment:

Have a look at the documentation... - ops, is your code based on just this documentation? This is what I can read there:

message: 'Record ID: ' + event.detail.id,

Still doesn't work?

  • This did not work. Now the toast message shows "New School Salesforce ID: undefined" and not the Salesforce ID. Since I am creating the records using lightning record form, I am not sure how to fetch the id.
    – Night Guy
    Feb 27, 2022 at 10:59

JavaScript has template literals you can use for this.

message: `New School Salesforce ID: ${event.id}`,

Also you create a link to the record in the toast message as well. See Displaying Links in Toasts section here.

  • Even after using message: New School Salesforce ID: ${event.id}, the toast message shows "New School Salesforce ID: undefined" and not the Salesforce ID.
    – Night Guy
    Feb 28, 2022 at 7:58
  • Then the event.id must be undefined. Can you post the html for the LWC.
    – Andrew L.
    Feb 28, 2022 at 14:16
  • I have already posted the html, js and xml in the question.
    – Night Guy
    Feb 28, 2022 at 14:31

Use : message: "New School Salesforce ID: "+ event.detail.id instead of event.detail.Id ( small letter "i" for id)

Worked for me.

  • 1
    OP already appears to be using id with the lower case "i". Is this a comment on one of the existing answers?
    – Derek F
    Dec 5, 2022 at 15:18
  • I added this as an answer to @Night Guy as he mentioned that previous solutions didn't work for him. And I faced the similar issue before the solution I posted...
    – PSS
    Jan 3 at 8:13

You must log in to answer this question.

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