Hi,
This example explains you how to create lead record from Lightning component.
here we did the following things
Component:leadCreation
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="LightningLeadCreatecls">
<!--including lightning styles-->
<ltng:require styles="{!$Resource.Lightning_slds+'/assets/styles/salesforce-lightning-design-system.css'}"/>
<ltng:require styles="{!$Resource.Lightning_slds+'/assets/styles/salesforce-lightning-design-system.min.css'}"/>
<!-- Preparation of lead object with fields-->
<aura:attribute name="leadObj" type="Lead" default="{'sobjectType':'lead',
'FirstName':'',
'LastName':'',
'Company':'',
'Email':''}"/>
<div class="slds">
<div class="slds-form-element">
<label class="slds-form-element__label" for="FirstName">First Name</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="FirstName" class="slds-input" value="{!v.leadObj.FirstName}" placeholder="First Name" />
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label" for="LastName">Last Name</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="LastName" class="slds-input" value="{!v.leadObj.LastName}" placeholder="Last Name" />
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label" for="Company">Company</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="Company" class="slds-input" value="{!v.leadObj.Company}" placeholder="Company" />
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label" for="Email">Email</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="Email" class="slds-input" value="{!v.leadObj.Email}" placeholder="Email" />
</div>
</div>
<div class="slds-form-element">
<div class="slds-form-element__control">
<ui:button label="Save" press="{!c.save}"/>
</div>
</div>
</div>
</aura:component>
Controller:
-----------
({
save : function(component, event, helper) {
var action = component.get("c.creatLeadRecord");
action.setParams({"leadObj":component.get("v.leadObj")});
action.setCallback(this,function(result){
component.set("v.isShow",false);
var leadId = result.getReturnValue();
alert('leadId'+leadId);
});
$A.enqueueAction(action);
}
})
App:
------
<aura:application >
<c:LeadCreation />
</aura:application>
output:
--------
This example explains you how to create lead record from Lightning component.
here we did the following things
- one apex class with aura enabled methods which has lead insert.
- one Lightning component you can see previous example how to create a component
- included lightning styles from lightning design system.
- include controller with lightning component to invoke apex method and process
- created one app to execute component
Apex class:
public class LightningLeadCreatecls {
@auraenabled
public static Id creatLeadRecord(Lead leadObj){
upsert leadObj;
return leadObj.id;
}
}
Component:leadCreation
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="LightningLeadCreatecls">
<!--including lightning styles-->
<ltng:require styles="{!$Resource.Lightning_slds+'/assets/styles/salesforce-lightning-design-system.css'}"/>
<ltng:require styles="{!$Resource.Lightning_slds+'/assets/styles/salesforce-lightning-design-system.min.css'}"/>
<!-- Preparation of lead object with fields-->
<aura:attribute name="leadObj" type="Lead" default="{'sobjectType':'lead',
'FirstName':'',
'LastName':'',
'Company':'',
'Email':''}"/>
<div class="slds">
<div class="slds-form-element">
<label class="slds-form-element__label" for="FirstName">First Name</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="FirstName" class="slds-input" value="{!v.leadObj.FirstName}" placeholder="First Name" />
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label" for="LastName">Last Name</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="LastName" class="slds-input" value="{!v.leadObj.LastName}" placeholder="Last Name" />
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label" for="Company">Company</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="Company" class="slds-input" value="{!v.leadObj.Company}" placeholder="Company" />
</div>
</div>
<div class="slds-form-element">
<label class="slds-form-element__label" for="Email">Email</label>
<div class="slds-form-element__control">
<ui:inputText aura:id="Email" class="slds-input" value="{!v.leadObj.Email}" placeholder="Email" />
</div>
</div>
<div class="slds-form-element">
<div class="slds-form-element__control">
<ui:button label="Save" press="{!c.save}"/>
</div>
</div>
</div>
</aura:component>
Controller:
-----------
({
save : function(component, event, helper) {
var action = component.get("c.creatLeadRecord");
action.setParams({"leadObj":component.get("v.leadObj")});
action.setCallback(this,function(result){
component.set("v.isShow",false);
var leadId = result.getReturnValue();
alert('leadId'+leadId);
});
$A.enqueueAction(action);
}
})
App:
------
<aura:application >
<c:LeadCreation />
</aura:application>
output:
--------
thank you for kindly information
ReplyDeletebest online trainings!
thank you for information
ReplyDeletebest online trainings
https://salesforce-walker.blogspot.in/2016/08/create-lead-record-using-lightning.html?showComment=1478174941430#c959419562638357894
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteBest Information thank you saleforce online training Hyderabad
ReplyDeleteNice post.
ReplyDeletecoursquare smart class
coursquare learning
How do we save custom field(check box with multiple options) on lead object on this lightning component or page ?
ReplyDeleteit is returning a null value for me- somebody please assist.
ReplyDeletei am trying to create a record through a form in custom object. using the similar approach . but it is not creating any record and it is returning me a null value.
Could you please help me with code.
DeleteDid you ever solve this?
DeleteThis code is very helpful but i want to get the detail page when we click on save button .
ReplyDeletePlease let me know
Thank you.
Thanks, this is generally helpful.
ReplyDeleteStill, I followed step-by-step your method in this
salesforce training
salesforce online training India
salesforce online training
learn salesforce online
salesforce course