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
Arjuna1900Arjuna1900 

Please Resolve THE error in this below code ASAP [LWC PROBLEM]

TEMPLATECODE:
<template>
    <lightning-card title="Create custom lookup on contact object" >
   
        <div class="slds-p-horizontal_small">
            <c-lwc-product-lookup onselected={myLookupHandle}></c-lwc-product-lookup>
            <c-lwc-quotes-lookup onselected={myQuoteLookupHandle}></c-lwc-quotes-lookup>
           
            <lightning-input label="Sales Price"
                             value={quoteRecord.salesprice}
                             onchange={handleSalesChange}
                             class="slds-m-bottom_x-small slds-p-horizontal_small slds-form-element">
            </lightning-input>                        
            <lightning-input label="Quantity"
                             value={quoteRecord.quantity}
                             onchange={handleQuantityChange}
                             class="slds-m-bottom_x-small slds-p-horizontal_small slds-form-element">
            </lightning-input>
            <lightning-input label="Discount"
                             value={quoteRecord.discount}
                             onchange={handleDiscountChange}
                             class="slds-m-bottom_x-small slds-p-horizontal_small slds-form-element">
            </lightning-input>            
           
            <lightning-button label="Submit"
                              variant="brand"
                              onclick={createLookupContactAction}
                              class="slds-m-bottom_x-small slds-p-horizontal_small slds-form-element">
            </lightning-button>                    
        </div>
   
</lightning-card>
</template>

JSCODE:
import { LightningElement,track } from 'lwc';
import { createRecord } from 'lightning/uiRecordApi';

import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
 import QUOTE_LINE_OBJECT from '@salesforce/schema/QuoteLineItem';
import salesPriceField from '@salesforce/schema/QuoteLineItem.UnitPrice';
import  quantityField from '@salesforce/schema/QuoteLineItem.Quantity';
import discountField from '@salesforce/schema/QuoteLineItem.Discount';
import productfieldId from '@salesforce/schema/QuoteLineItem.Product2Id';

import quotefieldId from '@salesforce/schema/QuoteLineItem.QuoteId';

export default class TESTDEAFYULTQUOTESAVE extends NavigationMixin(LightningElement) {
    @track selectedProductId;
    @track selectedQuoteId;
    @track selectedpriceBookEntryId;
    @track quoteId;  
    @track quoteRecord={
       
        salesprice:salesPriceField,  
        quantity:quantityField,
        discount:discountField
    }
   
       
        handleSalesChange(event)
        {
            this.quoteRecord.salesprice=event.target.value;
            window.console.log('salesprice==>'+this.quoteRecord.salesprice);
        }
        handleQuantityChange(event)
        {
            this.quoteRecord.quantity=event.target.value;
            window.console.log('quantity==>'+this.quoteRecord.quantity);
        }
        handleDiscountChange(event)
        {
            this.quoteRecord.discount=event.target.value;
            window.console.log('discount==>'+this.quoteRecord.discount);
        }
        createLookupContactAction(){
            console.log(this.selectedProductId);
            console.log(this.selectedQuoteId);
            const fields = {};
            fields[salesPriceField.fieldApiName] = this.quoteRecord.salesprice;
            fields[quantityField.fieldApiName] = this.quoteRecord.quantity;
            fields[discountField.fieldApiName] = this.quoteRecord.discount;
            fields[productfieldId.fieldApiName] = this.selectedProductId;
            fields[quotefieldId.fieldApiName]=this.selectedQuoteId;
            fields[pricebookEntryIdField.fieldApiName]=this.selectedpriceBookEntryId;
            const recordInput = { apiName: QUOTE_LINE_OBJECT.objectApiName, fields };
            createRecord(recordInput)
                .then(contactobj=> {
                    this.quoteId = contactobj.id;
                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Contact record has been created',
                            variant: 'success',
                        }),
                    );
                    this[NavigationMixin.Navigate]({
                        type: 'standard__recordPage',
                        attributes: {
                            recordId: contactobj.id,
                            objectApiName: 'QuoteLineItem',
                            actionName: 'view'
                        },
                    });
   
   
   
                })
                .catch(error => {
   
 console.error("error: " + JSON.stringify(error));

                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Error creating record',
                            message: error.body.message,
                            variant: 'error',
                        }),
                    );
                });          
                }
    myLookupHandle(event){
        console.log(event.detail);
        this.selectedProductId = event.detail;
    }
    myQuoteLookupHandle(event){
        console.log(event.detail);
        this.selectedQuoteId = event.detail;
    }
}

ERROR WAS:
error: {"status":400,"body":{"message":"An error occurred while trying to update the record. Please try again.","statusCode":400,"enhancedErrorType":"RecordError","output":{"errors":[],"fieldErrors":{"PricebookEntryId":[{"constituentField":null,"duplicateRecordError":null,"errorCode":"REQUIRED_FIELD_MISSING","field":"PricebookEntryId","fieldLabel":"Price Book Entry ID","message":"Required fields are missing: [PricebookEntryId]"}]}}},"headers":{}}

Basically Ineed PriceBookEntryId which is missing How this field will added please tell me answer 

Thanks
Saurabh
mukesh guptamukesh gupta
Hi Arjuna,

Please follow below steps:-

1. First you need to create a new lookup for PricebookEntryId as you built for product lookup

like that:-
<c-lwc-pricebook-lookup onselected={myPricebookHandle}></c-lwc-pricebook-lookup>
and in controller:-
 
myPricebookHandle(event){
        console.log(event.detail);
        this.selectedPriceBookEntryId = event.detail;
    }

import { LightningElement,track } from 'lwc';
import { createRecord } from 'lightning/uiRecordApi';

import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import QUOTE_LINE_OBJECT from '@salesforce/schema/QuoteLineItem';
import salesPriceField from '@salesforce/schema/QuoteLineItem.UnitPrice';
import  quantityField from '@salesforce/schema/QuoteLineItem.Quantity';
import discountField from '@salesforce/schema/QuoteLineItem.Discount';
import productfieldId from '@salesforce/schema/QuoteLineItem.Product2Id';
import pricebookEntryIdField from '@salesforce/schema/QuoteLineItem.pricebookEntryId';
import quotefieldId from '@salesforce/schema/QuoteLineItem.QuoteId';

export default class TESTDEAFYULTQUOTESAVE extends NavigationMixin(LightningElement) {
    @track selectedProductId;
    @track selectedQuoteId;
    @track selectedpriceBookEntryId;
    @track quoteId;  
    @track quoteRecord={
       
        salesprice:salesPriceField,  
        quantity:quantityField,
        discount:discountField
    }
   
       
        handleSalesChange(event)
        {
            this.quoteRecord.salesprice=event.target.value;
            window.console.log('salesprice==>'+this.quoteRecord.salesprice);
        }
        handleQuantityChange(event)
        {
            this.quoteRecord.quantity=event.target.value;
            window.console.log('quantity==>'+this.quoteRecord.quantity);
        }
        handleDiscountChange(event)
        {
            this.quoteRecord.discount=event.target.value;
            window.console.log('discount==>'+this.quoteRecord.discount);
        }
        createLookupContactAction(){
            console.log(this.selectedProductId);
            console.log(this.selectedQuoteId);
            const fields = {};
            fields[salesPriceField.fieldApiName] = this.quoteRecord.salesprice;
            fields[quantityField.fieldApiName] = this.quoteRecord.quantity;
            fields[discountField.fieldApiName] = this.quoteRecord.discount;
            fields[productfieldId.fieldApiName] = this.selectedProductId;
            fields[quotefieldId.fieldApiName]=this.selectedQuoteId;
            fields[pricebookEntryIdField.fieldApiName]=this.selectedpriceBookEntryId;
            const recordInput = { apiName: QUOTE_LINE_OBJECT.objectApiName, fields };
            createRecord(recordInput)
                .then(contactobj=> {
                    this.quoteId = contactobj.id;
                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Success',
                            message: 'Contact record has been created',
                            variant: 'success',
                        }),
                    );
                    this[NavigationMixin.Navigate]({
                        type: 'standard__recordPage',
                        attributes: {
                            recordId: contactobj.id,
                            objectApiName: 'QuoteLineItem',
                            actionName: 'view'
                        },
                    });
   
   
   
                })
                .catch(error => {
   
 console.error("error: " + JSON.stringify(error));

                    this.dispatchEvent(
                        new ShowToastEvent({
                            title: 'Error creating record',
                            message: error.body.message,
                            variant: 'error',
                        }),
                    );
                });          
                }
    myLookupHandle(event){
        console.log(event.detail);
        this.selectedProductId = event.detail;
    }
    myQuoteLookupHandle(event){
        console.log(event.detail);
        this.selectedQuoteId = event.detail;
    }
    myPricebookHandle(event){
        console.log(event.detail);
        this.selectedpriceBookEntryId = event.detail;
    }
}

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh


 
Arjuna1900Arjuna1900
No MODULE named markup://c:lwcPricebookLookup found : [markup://c:tESTDEAFYULTQUOTESAVE


i got his problem tell me what i write lookuphandle of price book
Arjuna1900Arjuna1900
Attention all anyone have any solution for above error.. Please Resolve it Its Urgent


Thanks
Arjuna