You need to sign in to do that
Don't have an account?
Surender 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.
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.
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
In a component, you are using Lastname and phone but you need to use LastName and Phone in attribute and lightning:input tag.
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