0

I've made my first Lightning Web Component and it deploys and displays the column headers I have indicated but it isn't pulling in any data for the related quote line items. It looks like this currently:

Current view of component

Here is my apex controller to query the records;

public with sharing class QuoteLineItemController {
    @AuraEnabled(cacheable=true)
    public static List<QuoteLineItem> getQuoteLineItems(Id quoteId) {
        return [ SELECT 
        AdditionalNewsletterBrandsDetails__c,Additional_Information__c,Additional_Notes__c,
        Additional_Web_Brands_Details__c,Advice_Brand__c,Brand__c,
        Campaign_Name__c,Company_Sizes__c,Cost_Type__c,CQs__c,CreatedById,CreatedDate,Created_By__c,
        Creative_Format__c,Creative_Sizes__c,Creative_Source__c,Description,Device_Category__c,
        Discount,Display_Google_Form_Reminder__c,Email_Blast_Count_Required__c,Email_Blast_Record_Count__c,
        End_Date__c,Exact_Company_Sizes__c,Exact_Geography__c,Exact_Industries__c,Exact_Job_Titles__c,
        Flight_Dates__c,Frequency_Cap_Count__c,Frequency_Cap_Hours__c,Geography__c,Id,Industries__c,IsDeleted,
        Job_Titles__c,Keywords__c,LastModifiedById,LastModifiedDate,LastReferencedDate,LastViewedDate,
        LineNumber,Line_Item_ID__c,ListPrice,Media_Channels__c,Newsletter_Brands__c,OpportunityLineItemId,
        Potential_Clicks__c,PricebookEntryId,Price_per_Unit__c,Product2Id,Product_Family_Picklist__c,
        Product_Family__c,Product_ID__c,Quantity,Quote_ID__c,Rate_Factor__c,Rate__c,Rejected__c,
        Rejection_Notes__c,Reporting_Platform__c,Sales_Comments__c,ServiceDate,SortOrder,Start_Date_Time__c,
        Subtotal,SystemModstamp,Timeframe_Days__c,Topic_Area__c,TotalPrice,UnitPrice,Web_Brands__c 
            FROM QuoteLineItem
            WHERE Quote_ID__c = :quoteId];

    }
}

My HTML file:

<template>
    <div style="height: 300px;">
        <lightning-card>
            <template if:true={quotelineitems.data}>
                <lightning-datatable
                    key-field="Id"
                    data={quotelineitems.data}
                    columns={columns}>
                </lightning-datatable>
            </template>
        </lightning-card>
    </div>    
</template>

My javascript:

import { LightningElement, wire } from 'lwc';
import ID_FIELD from '@salesforce/schema/QuoteLineItem.Id';
import UNITPRICE_FIELD from '@salesforce/schema/QuoteLineItem.UnitPrice';
import getQuoteLineItems from '@salesforce/apex/QuoteLineItemController.getQuoteLineItems';
const COLUMNS = [
    { label: 'Id', fieldName: 'Id', type: 'text'},
    { label: 'Sales Price', fieldName: 'UnitPrice', type: 'currency' },
];
export default class quoteLineItemDataTableLWC extends LightningElement {
    columns = COLUMNS;
    @wire(getQuoteLineItems)
    quotelineitems;
}

And my meta XML

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

</LightningComponentBundle>

Please help! I'm very new to this so any suggestions you can give me would be great!

  • Side question: Is the custom field Quote_ID__c intentional in the soql query? QuoteLineItem had a standard QuoteId field. – akiradev Aug 8 at 21:45
2

Your getQuoteLineItems method takes a quoteId parameter.

Assuming the LWC is on a Quote record page, update your LWC wire call to include this parameter.

// Bind the recordId from the record page context
@api recordId;

@wire(getQuoteLineItems, { quoteId: '$recordId' })
quoteLineItems;
| improve this answer | |
  • I did that and it stopped returning records, is there an update I should be making to my SOQL query in the apex class as well? The Quote_ID__c is supposed to be in there it was a custom field I made to get the 18 digit ID – Mackenzie Jones Aug 10 at 14:48
  • This could be my bad, JS is case sensitive and I had camel cased the wired property. Other checks you could do is log this.recordId in renderedCallback to see if the recordId is binded correctly. The apex method looks ok, but might be worth writing a test method for it if you haven't already to see if the data comes back as expected. – akiradev Aug 10 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.