0

I have built a Lightning Web Component that communicates with other components and functions as a shopping cart for building Orders. On a button click an order needs to be created. Then the line items will be created and assigned the newly created OrderId. I have been able to successfully create Orders by following the documentation https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.data_salesforce_write

I am having trouble with creating order line items and dont know why. For testing, I have hardcoded the ids, quantities and prices. Am I overlooking something?

import { LightningElement, track, wire } from 'lwc';
import {registerListener, unregisterAllListeners} from 'c/pubsub';
import {CurrentPageReference} from 'lightning/navigation'; 
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { createRecord } from 'lightning/uiRecordApi';
import ORDERITEM_OBJECT from '@salesforce/schema/OrderItem';
import QUANTITY_FIELD from '@salesforce/schema/OrderItem.Quantity';
import ORDERID_FIELD from '@salesforce/schema/OrderItem.OrderId';
import UNITPRICE_FIELD from '@salesforce/schema/OrderItem.UnitPrice';
import PRODUCT2_FIELD from '@salesforce/schema/OrderItem.Product2Id';
import PBID_FIELD from '@salesforce/schema/OrderItem.PricebookEntryId';


export default class ShoppingCart extends LightningElement {


addOrderItems(){
        const products = {};
                products[UNITPRICE_FIELD.fieldApiName] = '25000';
                products[ORDERID_FIELD.fieldApiName] = '8010X0000082Va1QAE';
                products[QUANTITY_FIELD.fieldApiName] = '2';
                products[PRODUCT2_FIELD.fieldApiName] = '01t0X000008AclSQAS';
                products[PBID_FIELD.fieldApiName] = '01t0X000008AclSQAS';
                const productInput = { apiName: ORDERITEM_OBJECT.objectApiName, products };

        createRecord(productInput)

            .then(orderItem => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Success',
                        message: ' Order Items created',
                        variant: 'success'
                    })
                );

            })

            .catch(error => {
                this.dispatchEvent(
                    new ShowToastEvent({
                        title: 'Error creating record',
                        message: error.body.message,
                        variant: 'error',
                    }),
                );
            });
    }

}


2
  • Anything in catch block? Commented Dec 31, 2019 at 19:38
  • @PranayJaiswal Nothing in the catch block...
    – Jordan
    Commented Jan 1, 2020 at 14:44

0

You must log in to answer this question.

Browse other questions tagged .