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
Surender reddy SalukutiSurender reddy Salukuti 

.Lightning_sobject

Hi every one 
i am new to lightning 
actually my intention is inseart a contact record 

i wrote component
<aura:component controller="Lightning_sobject" >
    <aura:attribute name="con" type="contact" default="{'sObjectType':'contact','Lastname':'','FirstName':'','phone':''}"/>
    <aura:attribute name="result" type="string"/>
    
    <div class="Box">
        <lightning:card title="contact">
        <div class="mybox">
            <lightning:input label="first Name" value="{!v.con.Lastname}"/>
            <lightning:input label="Last Name" value="{!v.con.FirstName}"/>
            <lightning:input label="phone" value="{!v.con.phone}"/>
            </div>
            <aura:set attribute="footer">
                <lightning:button label="submit" onclick="{!c.show}"/>
            </aura:set>
    </lightning:card>
        {!v.result}
        </div>
    </aura:component>
apex class
public class Lightning_sobject {
    
    @Auraenabled
    public static string create(contact con){
        insert con;
        string result;
        return result;
   }
}
controller

({
    show : function(component, event, helper) {
        var con=component.get("v.con");
        var action=component.get("c.create");
        action.setparams({"con":con});
        action.setCallback(this,function(response){
            var state =response.getState();
            if(state==="SUCCESS"){
               var result=response.getReturnValue();
                console.log('Result:'+result);
                component.set("v.result",result);
            }else{
                console.log('Failed');
            }
            
        });
        $A.enqueueAction(action);
          }
})
when after insertion when i am cicking submit button i am getting Error
This page has an error. You might just need to refresh it. Action failed: c:Sobject_ex$controller$show [action.setparams is not a function] Failing descriptor: {c:Sobject_ex$controller$show}
 
if any one know help me

Thank you 
Surender Reddy.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Surender,

Greetings to you!

As lightning is based on aura framework which is a type of JavaScript and JavaScript is case sensitive so lightning is case sensitive. You need to change a few things in component and controller.

In a controller, you are using setparams but you need to use setParams
({
    show : function(component, event, helper) {
        var con=component.get("v.con");
        var action=component.get("c.create");
        action.setParams({"con":con});
        action.setCallback(this,function(response){
            var state =response.getState();
            if(state==="SUCCESS"){
               var result=response.getReturnValue();
                console.log('Result:'+result);
                component.set("v.result",result);
            }else{
                console.log('Failed');
            }
            
        });
        $A.enqueueAction(action);
          }
})

In a component, you are using Lastname and phone but you need to use LastName and Phone in attribute and lightning:input tag.
 
<aura:component controller="Lightning_sobject" >
    
    <aura:attribute name="con" type="contact" default="{'sObjectType':'contact','LastName':'','FirstName':'','Phone':''}"/>
    <aura:attribute name="result" type="string"/>
    
    <div class="Box">
        <lightning:card title="contact">
            <div class="mybox">
                <lightning:input label="first Name" value="{!v.con.LastName}"/>
                <lightning:input label="Last Name" value="{!v.con.FirstName}"/>
                <lightning:input label="phone" value="{!v.con.Phone}"/>
            </div>
            <aura:set attribute="footer">
                <lightning:button label="submit" onclick="{!c.show}"/>
            </aura:set>
        </lightning:card>
        {!v.result}
    </div>
</aura:component>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Raj VakatiRaj Vakati
Use this code
 
public class Lightning_sobject {
    
    @Auraenabled
    public static string create(contact con){
        insert con;
        return  con.id;
   }
}
 
<aura:component controller="Lightning_sobject" >
    
    <aura:attribute name="con" type="contact" default="{'sObjectType':'contact','LastName':'','FirstName':'','Phone':''}"/>
    <aura:attribute name="result" type="string"/>
    
    <div class="Box">
        <lightning:card title="contact">
            <div class="mybox">
                <lightning:input label="first Name" value="{!v.con.LastName}"/>
                <lightning:input label="Last Name" value="{!v.con.FirstName}"/>
                <lightning:input label="phone" value="{!v.con.Phone}"/>
            </div>
            <aura:set attribute="footer">
                <lightning:button label="submit" onclick="{!c.show}"/>
            </aura:set>
        </lightning:card>
       new Contact Id - :  {!v.result}
    </div>
</aura:component>
 
({
    show : function(component, event, helper) {
        var con=component.get("v.con");
        var action=component.get("c.create");
        action.setParams({"con":con});
        action.setCallback(this,function(response){
            var state =response.getState();
            if(state==="SUCCESS"){
               var result=response.getReturnValue();
                console.log('Result:'+result);
                component.set("v.result",result);
            }else{
                console.log('Failed');
            }
            
        });
        $A.enqueueAction(action);
          }
})