enter image description here

Above error is coming in console.

Below is the code:

@track calculateTotal;
@track error;
@track results;
@track _shippingcharges;
@track _salestax;
@track _productarray;

@api set shippingcharges(value) {
    this._shippingcharges = value;
get shippingcharges() {
    return this._shippingcharges;
@api set salestax(value) {
    this._salestax = value;
get salestax() {
    return this._salestax;
@api set productarray(value) {
    this._productarray = value;
get productarray() {
    return this._productarray;
doCalc() {
    if ((this.shippingcharges !==undefined) && (this.salestax !== undefined) && (JSON.parse(JSON.stringify(this.productarray)) !== undefined)) {
        console.log(JSON.parse(JSON.stringify(this.productarray))); // getting error on using JSON
        console.log('I am in doCalc');
        calculateTotal({ shippingcharges: this.shippingcharges, salestax: this.salestax, pricebookProductArray: JSON.parse(JSON.stringify(this.productarray)) })
            .then(result => {
                this.calculateTotal = result;
            .catch(error => {
                this.error = error;

Also, records in productArray are going to apex, but with all fields null. (the main problem)

Below is apex method:

    public static decimal calculateTotal(Decimal shippingcharges, Decimal salestax, List<PriceBookEntry2> pricebookProductArray){
        Decimal total = 0;
        Decimal calculatedPrice = 0;
        for(PriceBookEntry2 pbe : pricebookProductArray){
            total = total + pbe.subtotal;


        calculatedPrice = total + salestax + shippingcharges;

        return calculatedPrice;  

public class PriceBookEntry2{
         public String priceBookEntryId; 
         public String productId; 
         public String productName; 
         public String productCode;
         public String priceBookId;
         public String priceBookName;
         public Decimal priceUnit; 
         public Integer quantity;
         public Decimal subtotal;

         public PriceBookEntry2(){
             priceUnit = 0;
             quantity = 0;
             subtotal = 0;
  • 1
    i can see two things in your code, your apex method name defined during import of apex method and a public property matches. It might create issue. Also, can you put a log in your js and see if the array has value before calling apex Commented Jul 8, 2020 at 15:15
  • I have changed the name of public property on your suggestion. There is already a log inside doCalc() just before calling calculateTotal apex method. It is giving me correct record with values in fields, but also along with an error in console mentioned here in post at top most.
    – user75908
    Commented Jul 8, 2020 at 15:24

1 Answer 1


will always return a string, so you're entering your if block too early. Rewrite your if as:

if(typeof this.shippingcharges == "number" && typeof this.salestax == "number" && this.productarray instanceOf Array) {
  • I made the change, also I am getting complete data in console.log, number of records passing in apex is correct, but value of all fields are null.
    – user75908
    Commented Jul 10, 2020 at 15:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .