Skip to main content
added 5 characters in body
Source Link
sfdcfox
  • 501.7k
  • 21
  • 473
  • 828

It sounds like your code is running into a race condition. I'd write this so that the calculation occurs whenever all the data is available:

_shippingcharges;
_salestax;
_productarray;
@api set shippingcharges(value) {
    this._shippingcharges = value;
    this.doCalc();
}
get shippingcharges() {
    return this._shippingcharges;
}
@api set salestax(value) {
    this._salestax = value;
    this.doCalc();
}
get salestax() {
    return this._salestax;
}
@api set productarray(value) {
    this._productarray = value;
    this.doCalc();
}
get productarray() {
    return this._productarray;
}
doCalc() {
    if (this.shippingcharges && this.salestax && this.productarray) {
        calculateTotal({ shippingcharges: this.shippingcharges, salestax: this.salestax, pricebookProductArray: this.productarray })
            .then(result => {
                this.calculateTotal = result;
            })
            .catch(error => {
                this.error = error;
            });
    
    }
}

It sounds like your code is running into a race condition. I'd write this so that the calculation occurs whenever all the data is available:

_shippingcharges;
_salestax;
_productarray;
@api set shippingcharges(value) {
    this._shippingcharges = value;
    this.doCalc();
}
get shippingcharges() {
    return _shippingcharges;
}
@api set salestax(value) {
    this._salestax = value;
    this.doCalc();
}
get salestax() {
    return this._salestax;
}
@api set productarray(value) {
    this._productarray = value;
    this.doCalc();
}
get productarray() {
    return this._productarray;
}
doCalc() {
    if (this.shippingcharges && this.salestax && this.productarray) {
        calculateTotal({ shippingcharges: this.shippingcharges, salestax: this.salestax, pricebookProductArray: this.productarray })
            .then(result => {
                this.calculateTotal = result;
            })
            .catch(error => {
                this.error = error;
            });
    
    }
}

It sounds like your code is running into a race condition. I'd write this so that the calculation occurs whenever all the data is available:

_shippingcharges;
_salestax;
_productarray;
@api set shippingcharges(value) {
    this._shippingcharges = value;
    this.doCalc();
}
get shippingcharges() {
    return this._shippingcharges;
}
@api set salestax(value) {
    this._salestax = value;
    this.doCalc();
}
get salestax() {
    return this._salestax;
}
@api set productarray(value) {
    this._productarray = value;
    this.doCalc();
}
get productarray() {
    return this._productarray;
}
doCalc() {
    if (this.shippingcharges && this.salestax && this.productarray) {
        calculateTotal({ shippingcharges: this.shippingcharges, salestax: this.salestax, pricebookProductArray: this.productarray })
            .then(result => {
                this.calculateTotal = result;
            })
            .catch(error => {
                this.error = error;
            });
    
    }
}
Source Link
sfdcfox
  • 501.7k
  • 21
  • 473
  • 828

It sounds like your code is running into a race condition. I'd write this so that the calculation occurs whenever all the data is available:

_shippingcharges;
_salestax;
_productarray;
@api set shippingcharges(value) {
    this._shippingcharges = value;
    this.doCalc();
}
get shippingcharges() {
    return _shippingcharges;
}
@api set salestax(value) {
    this._salestax = value;
    this.doCalc();
}
get salestax() {
    return this._salestax;
}
@api set productarray(value) {
    this._productarray = value;
    this.doCalc();
}
get productarray() {
    return this._productarray;
}
doCalc() {
    if (this.shippingcharges && this.salestax && this.productarray) {
        calculateTotal({ shippingcharges: this.shippingcharges, salestax: this.salestax, pricebookProductArray: this.productarray })
            .then(result => {
                this.calculateTotal = result;
            })
            .catch(error => {
                this.error = error;
            });
    
    }
}