You need to sign in to do that
Don't have an account?
SFDC12
my requirement
Hi everyone,am trying to create a contact related to paritcular account in lightning .tried so far..,and embeded this component in accountrecord page ,but unable to save. can someone help me out .
Thanks in Advance.
apex:
public class QuickCreatecontact {
@AuraEnabled
public static void createcontact(contact con,Id AccountId){
con.AccountId=AccountId;
insert con;
}
}
component:
<aura:component controller="QuickCreatecontact" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
<aura:attribute name="createcontact" type="contact"/>
<aura:attribute name="accountId" type="string"/>
<!-- <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>-->
<div>
<lightning:input type="text" name="{!v.createcontact.LastName}" label="Enter LastName" />
<lightning:input type="text" name="{!v.createcontact.FirstName}" label="Enter firstName"/>
<lightning:input type="phone" name="{!v.createcontact.phone}" label="Enter phone"/>
</div>
<div>
<lightning:button label="save" variant="brand" onclick="{!c.dosave}"/>
</div>
</aura:component>
js:
({
dosave : function(component, event, helper) {
var action=component.get("c.createcontact");
action.setParams({
con:component.get("v.createcontact"),
Id:component.get("v.accountId")
});
action.setCallback(this,function(response){
var state=response.getState();
if(state==='SUCCESS'){
var result=response.getReturnValue();
alert('SUCCESS');
}else if(state==='INCOMPLETE'){
}
});
$A.enqueueAction(action);
}
})
Thanks in Advance.
apex:
public class QuickCreatecontact {
@AuraEnabled
public static void createcontact(contact con,Id AccountId){
con.AccountId=AccountId;
insert con;
}
}
component:
<aura:component controller="QuickCreatecontact" implements="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
<aura:attribute name="createcontact" type="contact"/>
<aura:attribute name="accountId" type="string"/>
<!-- <aura:handler name="init" value="{!this}" action="{!c.doinit}"/>-->
<div>
<lightning:input type="text" name="{!v.createcontact.LastName}" label="Enter LastName" />
<lightning:input type="text" name="{!v.createcontact.FirstName}" label="Enter firstName"/>
<lightning:input type="phone" name="{!v.createcontact.phone}" label="Enter phone"/>
</div>
<div>
<lightning:button label="save" variant="brand" onclick="{!c.dosave}"/>
</div>
</aura:component>
js:
({
dosave : function(component, event, helper) {
var action=component.get("c.createcontact");
action.setParams({
con:component.get("v.createcontact"),
Id:component.get("v.accountId")
});
action.setCallback(this,function(response){
var state=response.getState();
if(state==='SUCCESS'){
var result=response.getReturnValue();
alert('SUCCESS');
}else if(state==='INCOMPLETE'){
}
});
$A.enqueueAction(action);
}
})
Am seeing the below problems in your code:
Problem 1:
Specify the default values:
Problem 2:
you have to use the value in lightning:input tag... But you are using the name to get the input.
Problem 3:
setParams key needs to be the exact param name mentioned in apex class:
Also use the component.get("v.recordId") to get the current account Id.
Component File:
JS File :
Thanks,
Maharajan.C
All Answers
Can you add the Lightning Inspector for Chrome and see what error it shows when you click save?
Related: https://www.sfdckid.com/2019/08/salesforce-lightning-component-to-display-contacts.html
Note: Dont forget to pass the {!v.Recordid} this is important, please do check you are getting the record id with alert
Thanks and Regrads
karimulla syed
https://www.linkedin.com/in/karimulla-syed-191943153/
can you provide me a Screenshot of your Error?
I guess you are not providing the correct account Id, make sure you should give a exact Id of a account record in your salesforce
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi
Am seeing the below problems in your code:
Problem 1:
Specify the default values:
Problem 2:
you have to use the value in lightning:input tag... But you are using the name to get the input.
Problem 3:
setParams key needs to be the exact param name mentioned in apex class:
Also use the component.get("v.recordId") to get the current account Id.
Component File:
JS File :
Thanks,
Maharajan.C
Thanks in Advance.