I try to write something to the database soql in JS, but it not works. When I click to the button 'Add to Cart' then is called handlePlaceOrder(). Here is called Apex method placeOrder('hello') with parameter String. And then it crashed "an internal server error". When I executed only Apex method placeOrder('Order01') in Developer Console, it works, writes nameOfOrder to the database.
Here are codes:
html (OK):
<template>
<div class="shopping-cart">
<template if:true={messageFromMain}>
<div class="container">
<h1>Items in Cart</h1>
<lightning-card title="Shopping cart">
<lightning-button
class="slds-m-left_x-small"
label="Place order"
title="Place order"
variant="success"
onclick={handlePlaceOrder}>
</lightning-button>
</lightning-card>
</div>
</template>
<template if:false={messageFromMain}>
<h1>Select the shoes</h1>
</template>
</div>
</template>
JS (bug):
import { LightningElement, api, wire } from 'lwc';
import placeOrder from '@salesforce/apex/ProductMaster.placeOrder';
export default class ShoppingCart extends LightningElement {
nameOfOrder;
@api messageFromMain;
@wire(placeOrder, { nameOfOrder: '$nameOfOrder'})
// handle click to button Place order
handlePlaceOrder() {
console.log('It was pressed button \'Add to Cart\'.');
placeOrder('hello');
}
}
Apex (OK):
@AuraEnabled(cacheable=true)
public static void placeOrder(String nameOfOrder) {
Shop_Order__c newOrder = new Shop_Order__c(
Text__c = nameOfOrder
);
insert newOrder;
}
Error:
Error: An internal server error has occurred
Error ID: 185265246-97831 (-1502885840)
at U.B.mk (https://static.lightning.force.com/eu40/auraFW/javascript/Q8onN6EmJyGRC51_NSPc2A/aura_prod.js:656:438)
What is not correct on this JavaScript code? Here is an example with similar problem.

