I have a use case in which I need to the display the address fields(all custom fields with the same API name in both objects) of lead/ Account. Let's say if I'm on Enquiry object(custom object) then fetch the address details from lead else if I'm on Opportunity record page then fetch details from Accounts.
Here is my Component code
<aura:component controller="AESL_CommonUpdateAddressCtrl"
implements="flexipage:availableForRecordHome,force:hasRecordId,force:appHostable">
<aura:attribute name ="objName" type="String"/>
<aura:attribute name="title" type="String"/>
<aura:attribute name="objAddress" type="sObject"/>
<aura:handler name="init" value="{!this}" action="{!c.init}"/>
<Lightning:Card class="slds-card__body slds-card__body_inner"
title="{!v.title}">
<lightning:recordViewForm recordId="{!v.recordId}" objectApiName="{!v.objName}">
<div class="slds-box">
<span>These fields should not have a label</span>
<lightning:outputField fieldName="AESL_State__c" />
<lightning:outputField fieldName="AESL_City__c" />
</div>
</lightning:recordViewForm>
</Lightning:Card>
</aura:component>
My helper's init method is
getAddress.setCallback(this,function(response){
var state= response.getState();
if(state==='SUCCESS'){
var address = response.getReturnValue()
if(!$A.util.isEmpty(address)){
alert(JSON.stringify(address));
component.set('v.recordId',address[0]);
component.set('v.objName',address[1]);
if(address[1] === 'Lead'){
component.set('v.title','Lead Address Information');
}
else{
component.set('v.title','Student Address Information');
}
}
It's giving an error
Uncaught Action failed: lightning:recordViewForm$controller$handleRecordIdChange [Cannot read property 'getList' of null] Callback failed: apex://AESL_CommonUpdateAddressCtrl/ACTION$getObjectId
I tried to use breakpoints where the code is throwing this error. At
component.set('v.recordId',address[0]);
line it get redirected to aura_prod.js
Please correct me if I'm doing something wrong? or is it possible to achieve the scenario with this approach?