Stack Exchange
getting an exception while creating contact using apex in lwc: Unable to create Contact
import { LightningElement,api } from 'lwc';
import craeteContactHandler from "@salesforce/apex/craeteContactHandler.createContact";
import CONTACT_LASTNAME from "@salesforce/schema/Contact.LastName";
import CONTACT_FIRSTNAME from "@salesforce/schema/Contact.FirstName";
import CONTACT_PHONE from "@salesforce/schema/Contact.Phone";
import CONTACT_EMAIL from "@salesforce/schema/Contact.Email";
import CONTACT_ACCOUNTID from "@salesforce/schema/Contact.AccountId";
import { ShowToastEvent } from "lightning/platformShowToastEvent";


 export default class ContactCreationUsingApex extends LightningElement {

contactid;

contactRecord = {
    LastName: CONTACT_LASTNAME,
    FirstName: CONTACT_FIRSTNAME,
    Phone: CONTACT_PHONE,
    Email:CONTACT_EMAIL,
    AccountId:CONTACT_ACCOUNTID
  };

  handleFieldChange(event){
    this.contactRecord[event.target.name]=event.target.value;
    console.log(this.contactRecord)
  }
  onRecordSelection(event){
    console.log('datata',JSON.stringify(event.detail));
  this.contactRecord.AccountId=event.detail.selectedRecordList.Id;
  console.log('AccountIDDD',this.contactRecord);
  }

  handleSaveContact(){
    craeteContactHandler({contactRecObj:this.contactRecord})
    .then((result) => {
      this.contactRecord={}
      console.log('result result[0].Subject :' + JSON.stringify(result));
      const toastEvent = new ShowToastEvent({
        title: "Success!",
        message: "Contact Record is created successfully",
        variant: "success"
      });
      this.dispatchEvent(toastEvent);
    })
    .catch((error) => {
      this.error = error.message;
    });
  }

}
Apex:
public with sharing class craeteContactHandler {
@AuraEnabled(cacheable=false)
public static Contact createContact(Contact contactRecObj){

    System.debug('$$$$$datata'+contactRecObj);
    try {
        if(contactRecObj!=null){
            insert contactRecObj;
            }
            return contactRecObj;
    
        } catch (Exception ex) {
           throw new AuraHandledException(ex.getMessage());
        }
}

}

Even if you've already got an answer, - please add the Exception text to your question for future reference.

contactRecord = {
  LastName: CONTACT_LASTNAME,
  FirstName: CONTACT_FIRSTNAME,
  Phone: CONTACT_PHONE,
  Email:CONTACT_EMAIL,
  AccountId:CONTACT_ACCOUNTID
};

This is incorrect. Do not use tokens to initialize a record object. It should look like:
contactRecord = { sobjectType: 'Contact' };


I didn't get that ,Could you please provide the syntax to create records in lwc using apex

@Kishore { FirstName: 'Brian', LastName: 'Fear', Phone: '5551212', sobjectType: 'Contact' }
