• ekansh parnami
  • 0 Points
  • Member since 2017

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3
I am new to Web components and When ever i am trying to insert a record in Contact Object it was saving with only FirstName,Lastname,Physical Attributes but i am getting Input of all other fields  in Js but in debug Logs it was showing only data of FirstName,Lastname, not Physical Attributes in ApexClass why?? Can i Know the  reason Why??


    <lightning-card title="Insert Contact" icon-name="standard:contact">
            <div class="slds-p-around_x-small">
                <lightning-input label="FirstName" value={rec.FirstName} onchange={handleFirstNameChange}></lightning-input>
                <lightning-input label="LastName" value={rec.LastName} onchange={handleLastNameChange}></lightning-input>
                <lightning-input type="text" label="PhysicalAttributes" value={rec.PhysicalAttributes} onchange={handlePhysicalAttributesChange}></lightning-input><br/>
                <lightning-button label="Save" onclick={handleClick}></lightning-button>

Js File:

import { LightningElement,track } from 'lwc';
import createContact from '@salesforce/apex/insertContactApexWeb.saveContactRecord';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName__c';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName__c';
import PHYSICALATTRIBUTES_FIELD from '@salesforce/schema/Contact.Physical_Attributes__c';
export default class InsertContact extends LightningElement {
    @track firstname = FIRSTNAME_FIELD;
    @track lastname = LASTNAME_FIELD;
    @track physicalattributes = PHYSICALATTRIBUTES_FIELD;
    rec = {
        FirstName : this.firstname,
        LastName : this.lastname,
        PhysicalAttributes : this.physicalattributes
    handleFirstNameChange(event) {
        this.rec.FirstName = event.target.value;
        window.console.log("FirstName", this.rec.FirstName);
    handleLastNameChange(event) {
        this.rec.LastName = event.target.value;
        window.console.log("LastName", this.rec.LastName);
    handlePhysicalAttributesChange(event) {
        this.rec.PhysicalAttributes = event.target.value;
        window.console.log("PhysicalAttributes", this.rec.PhysicalAttributes);
    handleClick() {
        createContact({ con : this.rec })
            .then(result => {
                this.message = result;
                this.error = undefined;
                if(this.message !== undefined) {
                    this.rec.Name = '';
                    this.rec.Industry = '';
                    this.rec.Phone = '';
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Account created',
                            variant: 'success',
                window.console.log("result", this.message);
            .catch(error => {
                this.message = undefined;
                this.error = error;
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                window.console.log("error", JSON.stringify(this.error));

Apex Class:

public with sharing class insertContactApexWeb {
    public static void saveContactRecord(Contact con){
            insert con;
        catch(Exception ex) {
            throw new AuraHandledException(ex.getMessage());

I hope you can help. I'm wanting to create a LWC that uses the Datatable component with Inline Editing. but which get's the columns to display from the Lightning Page Parameters in the JS.Meta file Properties.

For instance, the Properties will have a field for inputting the fields we want to display in the related list in a comma deliminated fashion, and the passes these fields into the component / a dynamic piece of soql to be used in the Edtiable List.

All of the examples i have found have statically declared columns like below. But i really want these to be defined in the Lightning Builder Page so the component can be re-used on multiple objects and with different fields etc:

public with sharing class ContactController {

    public static List<Contact> getContactList() {
        return [SELECT Id, FirstName, LastName, Title, Phone, Email FROM Contact LIMIT 10];

    <lightning-card title="Datatable Example" icon-name="custom:custom63">

        <div class="slds-m-around_medium">
            <template if:true={contact.data}>
            <template if:true={contact.error}>
                <!-- handle Apex error -->

import { LightningElement, wire, track } from 'lwc';
import getContactList from '@salesforce/apex/ContactController.getContactList';
import { updateRecord } from 'lightning/uiRecordApi';
import { refreshApex } from '@salesforce/apex';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import FIRSTNAME_FIELD from '@salesforce/schema/Contact.FirstName';
import LASTNAME_FIELD from '@salesforce/schema/Contact.LastName';
import ID_FIELD from '@salesforce/schema/Contact.Id';

const COLS = [
    { label: 'First Name', fieldName: 'FirstName', editable: true },
    { label: 'Last Name', fieldName: 'LastName', editable: true },
    { label: 'Title', fieldName: 'Title' },
    { label: 'Phone', fieldName: 'Phone', type: 'phone' },
    { label: 'Email', fieldName: 'Email', type: 'email' }
export default class DatatableUpdateExample extends LightningElement {

    @track error;
    @track columns = COLS;
    @track draftValues = [];


    handleSave(event) {

        const fields = {};
        fields[ID_FIELD.fieldApiName] = event.detail.draftValues[0].Id;
        fields[FIRSTNAME_FIELD.fieldApiName] = event.detail.draftValues[0].FirstName;
        fields[LASTNAME_FIELD.fieldApiName] = event.detail.draftValues[0].LastName;

        const recordInput = {fields};

        .then(() => {
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Contact updated',
                    variant: 'success'
            // Clear all draft values
            this.draftValues = [];

            // Display fresh data in the datatable
            return refreshApex(this.contact);
        }).catch(error => {
                new ShowToastEvent({
                    title: 'Error creating record',
                    message: error.body.message,
                    variant: 'error'

Thanks in advance!!

Hi everyone can you please help me i am getting object object as return value.


js code :

import { LightningElement, wire, track } from 'lwc';
import mapDemo from '@salesforce/apex/Utility.mapDemo';
export default class LwcUtility extends LightningElement {
    @track name="Yogesh Upadhyay";
    @track message="Welcome";
    @track record;
    @track error;
    @track maps;
    @track conList= [
            name:'One two ka four',
            name:'One two ka five',
            name:'One two ka six',
            this.record = data;
            console.log("return is "+this.record);
            this.error= error;
            console.log("retrun is "+this.error);

apex :
public with sharing class Utility {
    public Utility() {
    public static map<String,Integer> mapDemo(){
        map<String,Integer> testmap = new map<String,Integer>();
        return testmap;