function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
niki s 7niki s 7 

Please help me with this lightning code

I have created one custom object using Lwc only I created a form. Now problem is that only I'd is getting printed.not the name. Can anybody help me . It's urgent
<template>
    <lightning-card title="Create Contact Record">
        <template if:true={conRecord}>
            <div class="slds-m-around--xx-large">
                <div class="container-fluid">
                    <div class="form-group">
                        <lightning-input label="Child Name" name="childName"  type="text"
                            value={conRecord.childName} onchange={handleChildNameChange}></lightning-input>
                    </div>
                </div>
                   
                <br />
                <lightning-button label="Submit" onclick={createRec} variant="brand"></lightning-button>
            </div>
        </template>
    </lightning-card>
</template>


js.
import {  LightningElement, track ,api } from 'lwc';
import {  ShowToastEvent } from 'lightning/platformShowToastEvent';
import insertDe from '@salesforce/apex/insertEvent.insertDe';
import Detail_OBJECT from '@salesforce/schema/Detail__c';
export default class insertEvent extends LightningElement {
   
   // @api childName;
    @track conRecord = Detail_OBJECT;
    handleChildNameChange(event) {
        this.conRecord.childName = event.target.value;
        window.console.log('child Name ==> ' + this.conRecord.childName);
     
    }

    createRec() {
        window.console.log('In createRec ===> ');
        insertDe({
            de: this.conRecord
            })
            .then(result => {
                // Clear the user enter values
                this.conRecord = {};
                window.console.log('result ===> ' + result);
                // Show success messsage
                this.dispatchEvent(new ShowToastEvent({
                    title: 'Success!!',
                    message: 'Contact Created Successfully!!',
                    variant: 'success'
                }), );
            })
            .catch(error => {
                this.error = error.message;
            });
    }
}


apex
public with sharing class insertEvent {
      @AuraEnabled
         public static void insertDe(Detail__c de) {

            try{  
               
                insert de;
                System.debug('Con '+de);
            }catch(Exception e){
                System.debug('--->'+e);
            }
            System.debug('Con '+de.Name);
            System.debug('Con '+de);
        }    
}

 
PRAKASH JADA 13PRAKASH JADA 13
Hi Niki,
Html:
----------------------
<template>
    <lightning-card title="Create Contact Record">
        <template if:true={conRecord}>
            <div class="slds-m-around--xx-large">
                <div class="container-fluid">
                    <div class="form-group">
                        <lightning-input label="Child Name" name="childName"  type="text"
                            value={conRecord} onchange={handleChildNameChange}></lightning-input> --> Modified Line
                    </div>
                </div>
                   
                <br />
                <lightning-button label="Submit" onclick={createRec} variant="brand"></lightning-button>
            </div>
        </template>
    </lightning-card>
</template>

JavaScript:
--------------------------
import {  LightningElement, track ,api } from 'lwc';
import {  ShowToastEvent } from 'lightning/platformShowToastEvent';
import insertDe from '@salesforce/apex/InsertEvent.insertDe';
import Detail_OBJECT from '@salesforce/schema/Detail__c';
export default class insertEvent extends LightningElement {
   
   // @api childName;
    @track conRecord = Detail_OBJECT;
    handleChildNameChange(event) {
        this.conRecord.Name = event.target.value; --> Modified Line
        window.console.log('child Name ==> ' + this.conRecord.Name);
      //  window.console.log(this.conRecord);
     
    }
    createRec() {
        window.console.log('In createRec ===> ' );
        insertDe({
            de: this.conRecord
            
            })
            .then(result => {
                // Clear the user enter values
                this.conRecord = {};
                window.console.log('result ===> ' + result);
                // Show success messsage
                this.dispatchEvent(new ShowToastEvent({
                    title: 'Success!!',
                    message: 'Contact Created Successfully!!',
                    variant: 'success'
                }), );
            })
            .catch(error => {
                this.error = error.message;
            });
    }
}

Apex class:
---------------------
There are no changes to your apex class.

Try this and you will get the apex to debug log with the name: the value you enter in the field.

I hope this  helps.