+ Start a Discussion

How do I update a record in the prodList?

Hi,this function takes as input a value (Quantity) this value must be subtracted from the value of the Available Quantity field contained in the "prodList" list filtered by the id, with the result of the subtraction "rquantity" must be inserted (update) in the list " v.prodList "passing the id. How can it be done?

yesBtn : function(component,event,helper){
        var qty=component.find("prova").get("v.value");
        var name=component.get("v.Name");
        var cr=component.get("v.id");
        var aquantity=component.get("v.AQuantity");
        console.log("id book "+component.get("v.id"));
            var toastEvent = $A.get("e.force:showToast");
                title : 'Error',
                message: 'the quantity you want exceeds that available',
                duration:' 5000',
                key: 'info_alt',
                type: 'Error',
                mode: 'pester'
            var rquantity=aquantity-qty;
            console.log("Available quantity - quantity = " +rquantity);

Sai PraveenSai Praveen (Salesforce Developers) 

This seems to be duplicate for the below question.

https://developer.salesforce.com/forums?dc=Apex_Code_Development#!/feedtype=SINGLE_QUESTION_DETAIL&dc=General_Development&criteria=ALLQUESTIONS&id=9062I000000UceP (https://developer.salesforce.com/forums?dc=Apex_Code_Development#!/feedtype=SINGLE_QUESTION_DETAIL&dc=General_Development&criteria=ALLQUESTIONS&id=9062I000000UceP)

Please allow some time for the experts to answer your question as duplicatating the question may cause the duplicate efforts.

Please close this question by marking it as best answer.

Elisa FieldsElisa Fields
It should work, check the snippet below, whatever value you enter into text box, it will increment from there only. There might be an issue with parsing in your code.
And try to give a simple code next time which can be understood and run easily. Also your code is complex, try to break it into different module, do not add this much code in one single file.   TellCulvers (https://www.tellculvers.onl/)
function AppViewModel() {

     this.ProductQty = ko.observable(0);

     this.removeFromList = function() {
       var currentVal = parseInt(this.ProductQty());
       if (currentVal >= 1) {
         this.ProductQty(currentVal - 1);

     this.addToCartViaOrderList = function() {
       var currentVal = parseInt(this.ProductQty());
       if (isNaN(currentVal)) {
         currentVal = 0;
       this.ProductQty(currentVal + 1);

    // Activates knockout.js
   ko.applyBindings(new AppViewModel());
.qty {
  font-size: 38px;
a {
  text-decoration: none;

<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.0.0/knockout-min.js"></script>
<div class="qty">
  <a href="#">
    <label data-bind="click: $root.removeFromList">-</label>
  <input type="text" data-bind="value: ProductQty" />
  <a href="#">
    <label data-bind="click: $root.addToCartViaOrderList">+</label>

Robert A. EliasRobert A. Elias
    Nice and amazing post this one is, thanks for sharing…
Dinar Guru (https://www.dinarguru.biz/)