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
gaganSFDCgaganSFDC 

Why this callback function return error while calling apex class lightning compoents ?

Hi All,
In lighting conponent's controller i have this code and i have a problem here that if i remove the if- condition then the callback return success and working fine but if not remove the if-condition then return error. All the consoles are also printing.
what am i doing wrong here ?

var validd = helper.validate(component,event);
        console.log('validd= '+validd);    // return true and all consoles are called
        if(validd){
            console.log('inside validd - if');
            var action = component.get("c.saveRecord");

             console.log('newCustBillObj='+newCustBillObj);
             console.log('newCustSoObj='+newCustSoObj);
            
            action.setParams({ "objCustBill" : newCustBillObj,   "objCustBillSO" : newCustSoObj   });
            action.setCallback(this, function(response){
                var state= response.getState();
                var result = response.getReturnValue();
                if(state === "SUCCESS"){                                    
                    alert('save-Record= '+result);
                }
                if(state === 'ERROR'){
                    alert('error in saving Record= '+result);
                }
            });
            
              
 console.log('before - enqueueAction');
            $A.enqueueAction(action); 
                
console.log('after - enqueueAction');
        }

<h1> pls help </h1>