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
ChinnoduChinnodu 

Action failed: Hunarsolution:contactrecordcreation$controller$dosave [action.setparams is not a function]

Hi All,

I am trying to create a new record , i am getting below error. please let me know where i did mistake. please help me 

Action failed: Hunarsolution:contactrecordcreation$controller$dosave [action.setparams is not a function] Failing descriptor: {Hunarsolution:contactrecordcreation$controller$dosave}

CODE :

Apex class :

public class Creatcontactdetails {

    @Auraenabled
    public static string createcontact(contact contobj)
    {
        insert contobj;
        return contobj.id;
    }
}


Component page :

<aura:component controller="Creatcontactdetails">
    <aura:attribute name="contactobj" type="contact" default="{'sobjecttype' :'contact',
                                                               'Firstname' :'',
                                                               'LastName'  : '',
                                                               'phone': ''}" />
    <aura:attribute name="contactID" type="string"/>
    <lightning:input value="{!v.contactobj.Firstname}" label="First Name" plaseholder="Enter first Name..."/>
    <lightning:input value="{!v.contactobj.LastName}" label="Last Name" plaseholder="Enter Last Name..."/>
    <lightning:input value="{!v.contactobj.Phone}" label="Phone" plaseholder="Enter Phone number..."/>
    
    <lightning:button variant="brand" label="save" title="save" onclick="{!c.dosave}"/>
    
    
</aura:component>



Controller 

({
    dosave : function(component, event, helper) {
        var action =component.get("c.createcontact");
        action.setparams({'contobj':component.get('v.contactobj')});
        action.setcallback(this,function(data)
        {
             component.set('v.contactID',data.getreturnvalue())              
       });
        $A.enqueueAction(action);
    }
})

Thanks 
Chinnodu
Bhawana Mehta SFDCBhawana Mehta SFDC
HI @Chinnodu,

Lightning Components are case sensitive. action.setparams isnt recognizable by LIghtning Component, replace it with action.setParams.
And also replace setcallback with setCallback.

With the above changes, you should be good to go!
 
({
    dosave : function(component, event, helper) {
        var action =component.get("c.createcontact");
        action.setParams({'contobj':component.get('v.contactobj')});
        action.setCallback(this,function(data)
        {
             component.set('v.contactID',data.getReturnValue())              
       });
        $A.enqueueAction(action);
    }
})