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
Shubham SonarShubham Sonar 

Issue in saving records with ligthning components.

I used the same code as given on trailhead, but either the method that needs to add a record is not getting called or maybe some other reason. The createExpense method is unable to create new Expense in SF object. Can anybody help me out?

Controller.js:
clickCreateExpense: function(component, event, helper) {
        if(helper.validateExpenseForm(component)){
            // Create the new expense
            var newExpense = component.get("v.newExpense");
            helper.createExpense(component, newExpense);
        }
    }

Helper.js:

createExpense: function(component, expense) {
         var action = component.get("c.saveExpense"); // call to controller method
        //set parameter value of that controller
        action.setParams({ "expense": expense });
        
        action.setCallback(this, function(response){
            var state = response.getState();
            
            if (component.isValid() && state === "SUCCESS") {
                var expenses = component.get("v.expenses");
                expenses.push(response.getReturnValue());
                component.set("v.expenses", expenses);
            }
    });
    $A.enqueueAction(action);
Apex Controller:
@AuraEnabled
    public static Expense__c saveExpense(Expense__c expense) {
        system.debug('saveExpense');
        // Perform isUpdatable() checking first, then
        upsert expense;
        return expense;
    }


 
sfdcMonkey.comsfdcMonkey.com
hi Shubham Sonar
can you please share your all  component code.
thanks