You need to sign in to do that
Don't have an account?
![Chinnoy Chinnoy](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Please help me on the below code.
Hi I am not able to save the record using lightning component.please find the code below.
Lightning Component:
<aura:component access="global" controller="LightningBloodDonorReg">
<aura:attribute name="bloodReg" type="WT_BloodDonor__c" default="{ 'sobjectType' : 'WT_BloodDonor__c' }"/>
<lightning:layout multipleRows="true">
<div class="div1">
<lightning:layoutItem flexibility="auto" padding="around-small" size="12">
JANASENA
</lightning:layoutItem></div>
<div class="div2">
<lightning:layoutItem flexibility="auto" padding="around-small" size="12">
My Life; My janasena
</lightning:layoutItem></div>
<lightning:layoutItem flexibility="auto" padding="around-small" size="12">
<lightning:layout >
<div style="padding-left:400px;">
<lightning:layoutItem size="4"></lightning:layoutItem>
</div>
<div style="background-color:orange;width:100%;">
<lightning:layoutItem flexibility="auto" padding="around-small" size="12" >
<ui:inputText label="Donor Name" aura:id="Donor Name" class="field" value="{!v.bloodReg.Name}" />
Blood Group <force:inputField aura:id="Donor Name" class="field" value="{!v.bloodReg.BloodGroup__c}" />
<ui:inputText label="Donor Phone" aura:id="Donor Name" class="field" value="{!v.bloodReg.PhoneNumber__c}" />
State <force:inputField aura:id="Donor Name" class="field" value="{!v.bloodReg.State__c}" />
District <force:inputField aura:id="Donor Name" class="field" value="{!v.bloodReg.District__c}" />
<!-- <ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>
<ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>
<ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>
<ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>-->
<ui:button label="Submit" class="slds-button slds-button--neutral" labelClass="label" press="{!c.createDonor}"/>
</lightning:layoutItem>
</div>
<lightning:layoutItem size="4"></lightning:layoutItem>
</lightning:layout>
</lightning:layoutItem>
</lightning:layout>
</aura:component>
.JS file
({
createDonor : function(component, event) {
var newDonor = component.get("v.bloodReg");
var action = component.get("c.createDonor");
action.setParams({
"bloodDonor": newDonor
});
action.setCallback(this, function(a) {
var state = a.getState();
if (state === "SUCCESS") {
var name = a.getReturnValue();
alert("success");
}
else{
alert("Failed");
}
});
$A.enqueueAction(action)
}
})
Class:
public class LightningBloodDonorReg {
@AuraEnabled
public static WT_BloodDonor__c bloodDonor { get; set; }
public LightningBloodDonorReg() {
bloodDonor = new WT_BloodDonor__c();
}
@AuraEnabled
public static WT_BloodDonor__c saveDetails() {
system.debug('bloodDonor'+bloodDonor);
Upsert bloodDonor;
system.debug('bloodDonor'+bloodDonor);
return bloodDonor ;
}
}
Lightning Component:
<aura:component access="global" controller="LightningBloodDonorReg">
<aura:attribute name="bloodReg" type="WT_BloodDonor__c" default="{ 'sobjectType' : 'WT_BloodDonor__c' }"/>
<lightning:layout multipleRows="true">
<div class="div1">
<lightning:layoutItem flexibility="auto" padding="around-small" size="12">
JANASENA
</lightning:layoutItem></div>
<div class="div2">
<lightning:layoutItem flexibility="auto" padding="around-small" size="12">
My Life; My janasena
</lightning:layoutItem></div>
<lightning:layoutItem flexibility="auto" padding="around-small" size="12">
<lightning:layout >
<div style="padding-left:400px;">
<lightning:layoutItem size="4"></lightning:layoutItem>
</div>
<div style="background-color:orange;width:100%;">
<lightning:layoutItem flexibility="auto" padding="around-small" size="12" >
<ui:inputText label="Donor Name" aura:id="Donor Name" class="field" value="{!v.bloodReg.Name}" />
Blood Group <force:inputField aura:id="Donor Name" class="field" value="{!v.bloodReg.BloodGroup__c}" />
<ui:inputText label="Donor Phone" aura:id="Donor Name" class="field" value="{!v.bloodReg.PhoneNumber__c}" />
State <force:inputField aura:id="Donor Name" class="field" value="{!v.bloodReg.State__c}" />
District <force:inputField aura:id="Donor Name" class="field" value="{!v.bloodReg.District__c}" />
<!-- <ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>
<ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>
<ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>
<ui:inputText label="Enter some text " class="field" value="Test Field" updateOn="click"/>-->
<ui:button label="Submit" class="slds-button slds-button--neutral" labelClass="label" press="{!c.createDonor}"/>
</lightning:layoutItem>
</div>
<lightning:layoutItem size="4"></lightning:layoutItem>
</lightning:layout>
</lightning:layoutItem>
</lightning:layout>
</aura:component>
.JS file
({
createDonor : function(component, event) {
var newDonor = component.get("v.bloodReg");
var action = component.get("c.createDonor");
action.setParams({
"bloodDonor": newDonor
});
action.setCallback(this, function(a) {
var state = a.getState();
if (state === "SUCCESS") {
var name = a.getReturnValue();
alert("success");
}
else{
alert("Failed");
}
});
$A.enqueueAction(action)
}
})
Class:
public class LightningBloodDonorReg {
@AuraEnabled
public static WT_BloodDonor__c bloodDonor { get; set; }
public LightningBloodDonorReg() {
bloodDonor = new WT_BloodDonor__c();
}
@AuraEnabled
public static WT_BloodDonor__c saveDetails() {
system.debug('bloodDonor'+bloodDonor);
Upsert bloodDonor;
system.debug('bloodDonor'+bloodDonor);
return bloodDonor ;
}
}
P.S.: Mark this as Best Answer if this reply helped you.
Thanks
Sachin Arora