Cannot read property 'get' of undefined. May I know if there is any troubleshooting points

694    Asked by GillianHamer in Salesforce , Asked on Jul 13, 2021

 I have mentioned everything correct, but still i am facing the issue, may i know if there are any trouble shooting points. code: Component:


js controller:
var selectedSOrg = component.find("selctOrg").get("v.value");
Error is: [Cannot read property 'get' of undefined]
Below is the code that i had in my controller and helper.
controller:
({ doinit : function(component, event, helper) { helper.fetchSBHelper(component, event, helper); } })
Helper:
({ fetchSBHelper : function(component, event, helper) { var sOrg = component.find("selctOrg"); var selectedSOrg = sOrg.get("v.value"); alert("selectedSOrg"+selectedSOrg); } })


Answered by Jiten Miglani

Based on the Aura component rendering life cycle, the Init event happens when the aura component construction finishes but before rendering child components. In your case, Combobox is rendered on the parent component after the Init event. In Init event, Combobox has not been rendered when you call component.find("selectedSOrg"), it returns undefined. Consequently, in this line:

    var selectedSOrg = sOrg.get("v.value"),

the code is trying to get value from an undefined object, that is why it throws an exception. Resolve “cannot read property 'get' of undefined” error: Just put the same code in the handle change js function, it will succeed.



Your Answer

Interviews

Parent Categories