Created
February 5, 2020 16:02
-
-
Save saicharanreddyk/02d05cb4b894672842b90f747eee6d81 to your computer and use it in GitHub Desktop.
Lightning - sObject Initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When you are initializing sObject like below | |
<aura:attribute name="acc" type="Account" /> --> This is like Account acc; There is no memory allocation happened | |
hence while entering values we will get null issue. | |
"TypeError: d is null | |
throws at https://domain.lightning.force.com/auraFW/javascript/5fuxCiO1mNHGdvJphU5ELQ/aura_prod.js:544:409" | |
Correct way of initializing is | |
<aura:attribute name="acc" type="Account" default="{sObjectType:'Account'}"/> | |
Account acc= new Accout(); equivalent. | |
Component | |
************************************************************************************ | |
<aura:component > | |
<aura:attribute name="acc" type="Account" default="{sObjectType:'Account'}"/> | |
<lightning:card iconName="standard:account"> | |
<aura:set attribute="actions"> | |
<lightning:button label="submit" onclick="{!c.submit}" /> | |
</aura:set> | |
<aura:set attribute="title"> | |
sObject<br/> | |
Account | |
</aura:set> | |
<lightning:input label="Account Name" value="{!v.acc.Name}"/> | |
<lightning:input label="Account Type" value="{!v.acc.type}"/> | |
<lightning:input label="Account Industry" value="{!v.acc.industry}"/> | |
</lightning:card> | |
</aura:component> | |
************************************************************************************ | |
Controller | |
************************************************************************************ | |
({ | |
submit : function(component, event, helper) { | |
var account = component.get("v.acc"); | |
console.log('Name'+account.Name); | |
console.log('Name'+account.type); | |
console.log('Name'+account.industry); | |
} | |
}) | |
************************************************************************************ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment