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
Jonathan Bissell 3Jonathan Bissell 3 

Related Record Data Table not Populating.

  • 2 Objects
    • 1 Design__c Record
    • 5 Array_Details__c
When on the Design__c record, I want to see a list of Array_Details__c, and be able to edit the records. 
 
HTML

<template>
    <lightning-datatable 
        data={data} 
        columns={columns} 
        key-field="Id" 
        onrowaction={handleRowAction} 
        onsave={handleSave} >
    </lightning-datatable>
</template>
 
.js

import { LightningElement, wire, api } from 'lwc';
import { getRecord, updateRecord,getRelatedRecords } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';

import Array_Details__c_OBJECT from '@salesforce/schema/Array_Details__c';
import Array_Details__c_LOOKUP_FIELD from '@salesforce/schema/Array_Details__c.Design__c';

import Name from '@salesforce/schema/Array_Details__c.Name';
import Array_System_Size__c from '@salesforce/schema/Array_Details__c.Array_System_Size__c';
import System_Size_kW__c from '@salesforce/schema/Array_Details__c.System_Size_kW__c';
import Installation_Type__c from '@salesforce/schema/Array_Details__c.Installation_Type__c';
import Roof_Material__c from '@salesforce/schema/Array_Details__c.Roof_Material__c';
import Module_Asset__c from '@salesforce/schema/Array_Details__c.Module_Asset__c';
import Number_of_Modules__c from '@salesforce/schema/Array_Details__c.Number_of_Modules__c';
import DV_Reviewed__c from '@salesforce/schema/Array_Details__c.DV_Reviewed__c';

export default class ArrayDetailsTable extends LightningElement {
    @api recordId;
    @wire(getRecord, { recordId: '$recordId', fields: [] })
    Design__c;
    @wire(getRelatedRecords, {
        recordId: '$recordId',
        relationshipApiName: Array_Details__c_LOOKUP_FIELD,
        objectApiName: Array_Details__c_OBJECT })
        Array_Details__c = { data: [] };


connectedCallback() {
   console.log(' connectedCallback Design Data', typeof this.Design__c, this.Design__c);
    }

renderedCallback() {
    console.log(' renderedCallback Design Data', typeof this.Design__c, this.Design__c);
    }

   Columns = [
    { label: 'Name', fieldName: Name, type: 'text', editable: false },
    { label: 'Array System Size', fieldName: Array_System_Size__c, type: 'text', editable: true },
    { label: 'System Size kW', fieldName: System_Size_kW__c, type: 'number', editable: true },
    { label: 'Installation Type', fieldName: Installation_Type__c, type: 'text', editable: true },
    { label: 'Roof Material', fieldName: Roof_Material__c, type: 'text', editable: true },
    { label: 'Module Asset', fieldName: Module_Asset__c, type: 'text', editable: true },
    { label: 'Number of Modules', fieldName: Number_of_Modules__c, type: 'number', editable: true },
    { label: 'DV Reviewed', fieldName: DV_Reviewed__c, type: 'date-local', editable: true }
];

handleRowAction(event) {
    const action = event.detail.template.action;
    const rowId = event.detail.template.row.Id;
    switch (action.name) {
        case 'edit':
            this.editRecord(rowId);
            break;
        case 'update':
            this.updateRecord(rowId);
            break;
    }
}


handleSave(event) {
    const draftValues = event.detail.template.draftValues;
    const rowId = event.detail.template.row.Id;
    this.updateRecord(draftValues,rowId);
}


updateRecord(draftValues, rowId) {
    updateRecord({ fields: draftValues, recordId: rowId })
        .then(() => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Record updated',
                    variant: 'success'
                })
            );
            // Refresh the view with the latest data
            return refreshApex(this.Array_Details__c);
        })
        .catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error updating record',
                    message: error.body.message,
                    variant: 'error'
                })
            );
        });
}
}
 
.XML

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="inlineEditRelatedList">
    <apiVersion>48.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__RecordPage</target>
    </targets>
</LightningComponentBundle>


 
Jonathan Bissell 3Jonathan Bissell 3
Nothing appears when I upload the LWC. I am getting 0 errors, and the console.log is not helping
Jonathan Bissell 3Jonathan Bissell 3
//Lightning Web Component (LWC) that displays a table of records from an object called "Array_Details__c" using the lightning-datatable component.
//The component is using the @wire decorator to fetch the records from the server using an Apex method called getArrayDetails.
//The component also allows the user to edit and update the records by handling row actions, such as clicking the "edit" button or "save" button on the table rows.
//The component also uses the updateRecord method from the lightning/uiRecordApi module to update the records on the server and the ShowToastEvent from the lightning/platformShowToastEvent module to display success or error messages to the user.
//Additionally, it is using the refreshApex method to refresh the wired data after updating record.
//Overall, the component is designed to display and allow editing of records from the Array_Details__c object, as well as providing feedback to the user through toasts about the success or failure of the update operation.
import { LightningElement, wire, api, track } from 'lwc';
import {getRecord,updateRecord } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
import getArrayDetails from '@salesforce/apex/ArrayDetailsController.getArrayDetails';
import Name from '@salesforce/schema/Array_Details__c.Name';
import Array_System_Size__c from '@salesforce/schema/Array_Details__c.Array_System_Size__c';
import System_Size_kW__c from '@salesforce/schema/Array_Details__c.System_Size_kW__c';
import Installation_Type__c from '@salesforce/schema/Array_Details__c.Installation_Type__c';
import Roof_Material__c from '@salesforce/schema/Array_Details__c.Roof_Material__c';
import Module_Asset__c from '@salesforce/schema/Array_Details__c.Module_Asset__c';
import Number_of_Modules__c from '@salesforce/schema/Array_Details__c.Number_of_Modules__c';
import DV_Reviewed__c from '@salesforce/schema/Array_Details__c.DV_Reviewed__c';
export default class ArrayDetailsTable extends LightningElement {
@track data;
@track Array_Details__c;
@api recordId;
@track dataLoading = true;
@wire(getRecord, { recordId: '$recordId', fields: [Array_System_Size__c] }) Design__c;

@wire(getArrayDetails, { recordId: '$recordId' })
wiredArrayDetails({ data, error }) {
    if (data) {
        this.Array_Details__c = data;
        this.dataLoading = false;
        console.log(' this.recordId', typeof this.recordId, this.recordId);
        console.log(' this.data', typeof this.data, this.data);
        console.log(' this.Array_Details__c', typeof this.Array_Details__c, this.Array_Details__c);
        console.log(' this.Array_Details__c', typeof this.Array_Details__c.data, this.Array_Details__c.data);
    }
    else if (error) {
        console.log(error);
        this.dataLoading = false;
    }
}
get Array_System_Size__c() {
    return getFieldValue(this.Design__c.data, Array_System_Size__c);
  }
   Columns = [
    { label: 'Name', fieldName: Name, type: 'text', editable: false },
    { label: 'Array System Size', fieldName: Array_System_Size__c, type: 'number', editable: true },
    { label: 'System Size kW', fieldName: System_Size_kW__c, type: 'number', editable: true },
    { label: 'Installation Type', fieldName: Installation_Type__c, type: 'text', editable: true },
    { label: 'Roof Material', fieldName: Roof_Material__c, type: 'text', editable: true },
    { label: 'Module Asset', fieldName: Module_Asset__c, type: 'text', editable: true },
    { label: 'Number of Modules', fieldName: Number_of_Modules__c, type: 'number', editable: true },
    { label: 'DV Reviewed', fieldName: DV_Reviewed__c, type: 'date-local', editable: true }
];


handleRowAction(event) {
    const action = event.detail.template.action;
    let rowId = event.detail.template.row.Id;
    if(action.name === 'edit'){
        this.editRecord(rowId);
    }
    else if(action.name === 'update' || action.name === 'save'){
        this.draftValues = event.detail.draftValues;
        this.updateRecord(rowId);
    }
}

// Second Event
editRecord(rowId) {
    let rows = [...this.Array_Details__c];
    let rowIndex = rows.findIndex(row => row.Id === rowId);
    rows[rowIndex].editable = true;
    this.Array_Details__c.data = rows;
}
// Third Event
updateRecord(rowId) {
    updateRecord({ fields: this.draftValues, recordId: rowId })
        .then(() => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Success',
                    message: 'Record updated',
                    variant: 'success'
                })
            );
            return refreshApex(this.wiredArrayDetails);
        })

// Forth Event
        .catch(error => {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error updating record',
                    message: error.body.message,
                    variant: 'error'
                })
            );
        });
    }
    handleCancel() {
        // refresh the data to discard changes
        return refreshApex(this.Array_Details__c);
    }
}




 
APEX Controller: 
public with sharing class ArrayDetailsController {
    @AuraEnabled(cacheable=true)
    public static List<Array_Details__c> getArrayDetails(Id recordId) {
        return [SELECT
        Name,
        Array_System_Size__c,
        System_Size_kW__c,
        Installation_Type__c,
        Roof_Material__c,
        Module_Asset__c,
        Number_of_Modules__c,
        DV_Reviewed__c
        FROM Array_Details__c
        WHERE Design__c = :recordId];
    }
}