To use my Lightning component for record pages of multiple types I need to load the record in a generic fashion.
<aura:component controller="MyCtrl" implements="force:hasRecordId,force:hasSObjectName,...">
<aura:attribute name="record" type="Map" />
<force:recordData recordId="{!v.recordId}" targetRecord="{!v.record}"
fields="{!(v.SObjectName == 'NS__MyObject__c') ? 'NS__lkp_Parent__c' : 'Id'}" />
...
</aura:component>
Not all of those type have a specific field called NS__lkp_Parent__c
. Lightning Data Service refused (fail) to load the whole record when I pass non-existing fields (which is bad!). Therefor I added a condition that checks the SObjectName before.
But this also fails with a generic error:
Unfortunately, there was a problem... Action failed: forceChatter:lightningComponent$controller$doInit [Error while creating content for lightning component quick action] quickActionHandlerHelper.js failed to create component - forceChatter:lightningComponent
What am I doing wrong?