+ Start a Discussion
Vishakha SomanVishakha Soman 

Error : Assertion Failed!

Hi,
I am facing the following error while updating the records.
Assertion Failed!: Unable to set value for key 'c.updateAccount'. Value provider does not implement 'set(key, value)'. : false Failing descriptor: {markup://c:TestUpdateComponent}
How will I set the Key can anyone please help
code :
Apex class:
public class TestUpdateController {
    
    @AuraEnabled
     public static List<Account> getAccListApex(List<Id> accountIds){
        List<Account> accList = new List<Account>();
        accList = [Select Id,Name, Type, Website,Phone,Industry from account limit 5];
        return accList;
     }
   Public static void updateAccount(string name, string website, string phone, string type){
        Account acc = new Account();
        acc.name = name;
        acc.website = website;
        acc.Phone = phone;
        acc.type = type;
        update acc;
   }
}
================================================
helper
({
    getAccountListhelper : function(component) {
        //add action to global action queue and that action will get Apex controller and fetch list
        var action = component.get("c.getAccListApex");
        action.setParams({accountIds : component.get("v.recordId")});
        action.setCallback(this,function(response){
            var state = response.getState();
            if(state === 'SUCCESS') {
                console.log("====response====",response.getReturnValue());
                component.set("v.accountList",response.getReturnValue());
                
            }
            else {
                alert('Error in getting data');
            }            
        });
        // Adding the action variable to the global action queue
        $A.enqueueAction(action);
    },
    saveAccount : function(component, event, helper){
        var action = component.set("c.updateAccount");
        action.setParams({
            name : component.set("v.Name"),
            website:component.set("v.Website"),
            Phone:component.set("v.Phone"),
            type:component.set("v.Type")
            
        });
         action.setCallback(this,function(response){
            var state = response.getState();
            if(state === 'SUCCESS') {
                console.log("====response====",response.getReturnValue());
                component.set("v.accountList",response.getReturnValue());
                
            }
            else {
                alert('Error in updating data');
            }            
        });
        // Adding the action variable to the global action queue
        $A.enqueueAction(action);
    }
    
})
----------------------------------------------------------------------------------
controller
({
    getAccountList : function(component, event, helper) {
        helper.getAccountListhelper(component);
        
    },
    createRecord : function (component, event, helper) {
        //global action only work under one app container
        alert('in global action');
        var createRecordEvent = $A.get("e.force:createRecord");
        createRecordEvent.setParams({
            "entityApiName": "Account",
            "defaultFieldValues":{
                'AccountId':component.get("v.recordId")
            }
        });
        createRecordEvent.fire();
    }   ,
    editAccount : function(component, event, helper) {
        //give refrence to button
        var btn = event.getSource();
        var name = btn.get('v.name');
        // Getting the record view form and the record edit form elements
        var recordViewForm = component.find('recordViewForm');
        var recordEditForm = component.find('recordEditForm'); 
        if(name=='edit') {
            $A.util.addClass(recordViewForm,'formHide');
            $A.util.removeClass(recordEditForm,'formHide');
            
            btn.set('v.name','save');
            btn.set('v.label','Save');
        }
        else if(name=='save') {
            // Calling save if the button is save
            helper.saveAccount(c<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" controller="TestUpdateController" access="global">
    
    <aura:attribute type="List" name="accountList"/>
    <aura:attribute name="Name" type="String" />
    <aura:attribute name="Phone" type="String"/>
    <aura:attribute name="Website" type="String" />
    <aura:attribute name="type" type="String"/>
    <aura:handler name="init" action="{!c.getAccountList}" value="{!this}" />
    <lightning:card title="Account">
        
        <p class="slds-p-horizontal_small">
            <div aura:id="recordViewForm">
                <aura:iteration items="{!v.accountList}" var="account">
                    <lightning:recordViewForm recordId="{!account.Id}" objectApiName="Account">
                        <div class="slds-box slds-theme_default">
                            <lightning:outputField fieldName="Name" />
                            <lightning:outputField fieldName="Website" />
                            <lightning:outputField fieldName="Phone" />
                            <lightning:outputField fieldName="Type" />
                        </div>
                    </lightning:recordViewForm>
                    <br />
                </aura:iteration>
            </div>
            <div aura:id="recordEditForm" class="formHide">
                <aura:iteration items="{!v.accountList}" var="account">
                    <lightning:recordEditForm recordId="{!account.Id}" objectApiName="Account">
                        <lightning:inputField fieldName="Name" />
                        <lightning:inputField fieldName="Website" />
                        <lightning:inputField fieldName="Phone" />
                        <lightning:inputField fieldName="Type" />
                        
                    </lightning:recordEditForm>
                </aura:iteration>
            </div>
        </p>
        <aura:set attribute="actions">
            <lightning:button label="New" onclick="{!c.createRecord}"/>
            <lightning:button variant="brand" label="Edit" name="edit" onclick="{!c.editAccount}"/>
        </aura:set>
        
    </lightning:card>
</aura:component>omponent, event, helper);
        }
    }
})
----------------------------------------------------------------------------------------
Thankyou in Advance
Best Answer chosen by Vishakha Soman
AbhinavAbhinav (Salesforce Developers) 
Hi Vishakha,

In your saveAccount function  you are you are using component.set("c.updateAccount");  You are calling apex method I think you should use component.get("c.updateAccount"); subsequently using get while setting params as well.
 
saveAccount : function(component, event, helper){
        var action = component.get("c.updateAccount");
        action.setParams({
            name : component.get("v.Name"),
            website:component.get("v.Website"),
            Phone:component.get("v.Phone"),
            type:component.get("v.Type")
            
        });

You updateAccount method  is also not been annotated aura enabled.

If it helps ,please mark it as best answer.

Thanks!