• Arjuna1900
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
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
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