You need to sign in to do that
Don't have an account?
FinnArildFluido
Passing and Accessing SObjects from lightning controller
I have a tricky little problem. I nest a couple of components, and in the top level component I am getting an SObject with a controller which works fine:
But however, in the handler - if I try to access the same variable I can access (both before and after the handler declaration) in the controller, I get null - both if I access the sobject directly, or a value on it (which is what I want to accomplish)
If I pass a String, it shows fine - but passing a sObject only seems to display values in the component and not it's controller. Anyone?
<aura:component > <aura:attribute name="sob" type="MySobject__c"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <h3>Checking ID: {!v.sob.Id}</h3> <c:mySubComponent sob="{!v.sob}"/> </aura:component>
My sub component looks like this, and also shows the Id fine (and the Name for that matter - however I have noticed here that the capitalization of those variables actually matter - but that is another kettle of fish):
<aura:component > <aura:attribute name="sob" type="MySobject__c"/> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <h3> check out the ID shows: {!v.sob.Id}</ </aura:component>
But however, in the handler - if I try to access the same variable I can access (both before and after the handler declaration) in the controller, I get null - both if I access the sobject directly, or a value on it (which is what I want to accomplish)
({ doInit : function(component, event, helper) { console.log('### this (and all variants of it) returns null: ' + component.get('v.sob.Id'); } })
If I pass a String, it shows fine - but passing a sObject only seems to display values in the component and not it's controller. Anyone?
This is a strategy I used a lot in Visualforce pages as well - and it turns out it is gonna work good for Lightning too.
All Answers
Please add a default value to the attribute. Here in your scenario, it was representing as the null object.
Here is my scenario please find the code.
Thanks
Pramodh
This is a strategy I used a lot in Visualforce pages as well - and it turns out it is gonna work good for Lightning too.