function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Srinivas223Srinivas223 

New values are not passing to the Apex class

Hello All,

I am creating a lightning component which is having few opportunity fields and a search button to search the records based on the values we have given in the fields. I rendered the list of opportunities in edit mode with a save button on each line item, so that if user want to modify anything on the oppty, he can do and click save which redirects him to the same page with the filters and list of opportunity reocds.
Everything is working fine. But, during the update call though i change values on a oppty, it is not considering the new values and updating the oppty with old values.

Here is my controller.js and Helper. I appreciate if anyone could help.
 
Controller.js

({
    doInit : function (component, event, helper) {
     
    
    }, 
    Search: function(component, event, helper) {
        var Owner = component.find('OwnerName');
        var Stage = component.find('searchStage');
        var Division = component.find('searchDivision');
        var Product = component.find('searchProductName');
        var isValueMissing = Owner.get('v.validity').valueMissing;
        // if value is missing show error message and focus on field
        if(isValueMissing) {
            Owner.showHelpMessageIfInvalid();
            Owner.focus();
        }else{
          // else call helper function 
            helper.SearchHelper(component, event);
        }
    },
    saveOpportunity : function(component, event, helper) {
        var opp = event.getSource().get("v.value");
        console.log('000000000 ' + opp)
        helper.updateHelper(component, event);
        component.search();

    }
})

Helper
({
	SearchHelper: function(component, event) {
        // show spinner message
         component.find("Id_spinner").set("v.class" , 'slds-show');
        var action = component.get("c.fetchOpportunities");
        action.setParams({
             
            'Owner': component.get("v.Owner"),
            'Stage': component.get("v.Stage"),
            'Division': component.get("v.Division"),
            'Product': component.get("v.ProductName")
        });
        action.setCallback(this, function(response) {
           // hide spinner when response coming from server 
            component.find("Id_spinner").set("v.class" , 'slds-hide');
            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                
                // if storeResponse size is 0 ,display no record found message on screen.
                if (storeResponse.length == 0) {
                    component.set("v.Message", true);
                } else {
                    component.set("v.Message", false);
                }
                
                // set numberOfRecord attribute value with length of return value from server
                component.set("v.TotalNumberOfRecord", storeResponse.length);
                
                // set searchResult list with return value from server.
                component.set("v.searchResult", storeResponse); 
                
            }else if (state === "INCOMPLETE") {
                alert('Response is Incompleted');
            }else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        alert("Error message: " + 
                                    errors[0].message);
                    }
                } else {
                    alert("Unknown error");
                }
            }
        });
        $A.enqueueAction(action);
    },
     updateHelper : function(component, event) {
        var oppty = event.getSource().get("v.value")
        console.log('oppty-- > ' + JSON.stringify(oppty));
        alert(oppty.StageName + ' -- ' + oppty.CloseDate);
        var action1 = component.get("c.saveOpp");
        action1.setParams({ 'op' : oppty ,
                            'Owner': component.get("v.Owner"),
                            'Stage': component.get("v.Stage"),
                            'Division': component.get("v.Division"),
                            'Product': component.get("v.ProductName")});
        action1.setCallback(this, function(response){
            var state = response.getState();
            if(state === "SUCCESS"){
                $A.get('e.force:refreshView').fire();
                console.log('server- > ' + response.getReturnValue());
                alert('Success');
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                } 
                else {
                   // console.log(resp.getReturnValue());
                }
            }
        });
        $A.enqueueAction(action1);
    }
})

Thank you!