I am getting an error while loading my aura components due to some of the lookup fields does not have any value. In our data model we have a lookup to an Account from Account. It's setup as a customer belonging to a company (employer) which is a lookup. The customer may or may not have an employer associated.
I have a following code in a component in which I am getting an error.
<aura:component controller="CustomerAccountsController" implements="flexipage:availableForAllPageTypes,force:hasRecordId">
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="acc" type="Account" />
<force:recordData aura:id="recordLoader"
recordId="{!v.recordId}"
targetFields="{!v.acc}"
fields="external_id__c, Employer__r.external_id__c"
recordUpdated="{!c.recordLoaded}"
/>
......
</aura:component>
The Employer__c lookup may or may not be present for all the individual account record. While loading a component error like following:
Action failed: c:accountDetails$controller$recordLoaded [Cannot read property 'external_id__c' of null]
Any idea how I can conditionally say in fields that if Employer is null then dont look for Employer__r.external_id__c.