Why getting uncaught type error: Cannot read property of Null in Lightning Input field?

963    Asked by AnneBell in Salesforce , Asked on Jul 19, 2021

Lightning force:record data shows following error: Uncaught Type Error: Cannot read property 'ValuePick__c' of null If I write like this error will disappear Why getting this error and how to resolve it?

Answered by Daniel BAKER

 force:recordData is missing a recordId, so there's nothing being pulled into v.UserSkillFields. Then when input is attempting to set input value equal to v.UserSkillFields.valueFields, it's drawing a null because nothing has been loaded into that attribute. Try including a recordId attribute in your force:recordData tag, and set it with either force:has recordedld or an init handler that sets the recordId attr with an Id string. If you're doing the latter you may have to reload recordData with .reloadRecord() to load associated field values. Then you should be able to set value of inputField.

** revision **

On further inspection, it seems like you're trying to default the GSS_User_Skill__c .ValuePick__c field to a parent record's field value. To resolve this error” cannot read property of null”,you can try the following set the parent record (UserSkillFields) id (in init) reload UserSkillFields (also in init) grab the reloaded UserSkillFields via component.get("v.UserSkillFields") explicitly pre-populate lightning:inputField value attribute with reloaded object's corresponding field value (via the force:recordEditForm onLoad() property)



Your Answer

Interviews

Parent Categories