1

I am building a lighting component which needs to iterate over a list with three different object types but I have run into a problem because I cannot write an aura if expression which checks the object type and displays the relevant fields (field names on the objects are different). I am at a loss here and cannot get over this limitation. Do I need to create some type of component that does the check? Any ideas? I have pasted below an example of the problem I am facing..

 <aura:iteration items="{!v.value}" var="paym" indexVar="indx">


        <lightning:formattedText value="{!paym.sobjecttype}"/>
        <aura:if isTrue="{!paym.sobjecttype == 'Loan_Principal_Payment__c'}">
            <div class="slds-grid slds-grid_align-space slds-theme_shade">
                <div class="slds-col"><span><b>Payment Status:</b> {!paym.Payment_Status__c}</span></div>
                <div class="slds-col"><span><b>Due Date:</b> {!paym.Due_Date__c}</span></div>
                <div class="slds-col"><span><b>Loan Principal Status:</b> {!paym.Loan_Principal_Status__c}</span></div>
                <div class="slds-col"><span><b>Payment Amount:</b> {!paym.Payment_Amount__c}</span></div>
                <div class="slds-col"><span><b>Merged Into LPP:</b> {!paym.Merged_Into_Principal_Payment__c}</span></div>
                <div class="slds-col"><span><b>Split From LPP:</b> {!paym.Split_From_Principal_Payment__c}</span></div>
                <div class="slds-col"><span><b>Cleared AdHoc Payment:</b> {!paym.Cleared_Adhoc_Payment__c}</span></div>
                <div class="slds-col"><span><b>Clearing Date:</b> {!paym.Clearing_Date__c}</span></div>
            </div>         
        </aura:if>
        <aura:if isTrue="{!paym.sobjecttype == 'Loan_Interest_Payment__c'}">
            <div class="slds-grid slds-grid_align-space slds-theme_shade">
                <div class="slds-col"><span><b>Payment Status:</b> {!paym.Payment_Status__c}</span></div>
                <div class="slds-col"><span><b>Due Date:</b> {!paym.Due_Date__c}</span></div>
                <div class="slds-col"><span><b>Loan Interest Status:</b> {!paym.Loan_Interest_Status__c}</span></div>
                <div class="slds-col"><span><b>Payment Amount:</b> {!paym.Payment_Amount__c}</span></div>
                <div class="slds-col"><span><b>Merged Into LIP:</b> {!paym.Merged_Into_Interest_Payment__c}</span></div>
                <div class="slds-col"><span><b>Split From LIP:</b> {!paym.Split_From_Interest_Payment__c}</span></div>
                <div class="slds-col"><span><b>Cleared AdHoc Payment:</b> {!paym.Cleared_Adhoc_Payment__c}</span></div>
                <div class="slds-col"><span><b>Clearing Date:</b> {!paym.Clearing_Date__c}</span></div>
            </div>         
        </aura:if>
        <aura:if isTrue="{!paym.sobjecttype == 'Loan_Fee_Payment__c'}">
            <div class="slds-grid slds-grid_align-space slds-theme_shade">
                <div class="slds-col"><span><b>Payment Status:</b> {!paym.Payment_Status__c}</span></div>
                <div class="slds-col"><span><b>Due Date:</b> {!paym.Due_Date__c}</span></div>
                <div class="slds-col"><span><b>Loan Fee Status:</b> {!paym.Loan_Fee_Status__c}</span></div>
                <div class="slds-col"><span><b>Payment Amount:</b> {!paym.Payment_Amount__c}</span></div>
                <div class="slds-col"><span><b>Merged Into LFP:</b> {!paym.Merged_Into_Fee_Payment__c}</span></div>
                <div class="slds-col"><span><b>Split From LFP:</b> {!paym.Split_From_Fee_Payment__c}</span></div>
                <div class="slds-col"><span><b>Cleared AdHoc Payment:</b> {!paym.Cleared_Adhoc_Payment__c}</span></div>
                <div class="slds-col"><span><b>Clearing Date:</b> {!paym.Clearing_Date__c}</span></div>
            </div>         
        </aura:if>
    </aura:iteration>

2 Answers 2

1

The name of the object member is sObjectType, not sobjecttype. See, for example, this Aura documentation:

<aura:attribute name="newContact" type="Contact"
        default="{ 'sobjectType': 'Contact' }" />

However, depending on how you populate these records, you may not be able to rely upon its presence. For example, records returned from Apex server-side controllers don't have sObjectType populated. Neither do records loaded by force:recordData.

If you need to disambiguate the contents of a heterogenous list of sObjects in JavaScript that don't already have the sObjectType member populated, you can take a variety of tactics.

  • If you're constructing the list in JavaScript from various Apex sources that themselves query homogenous lists, you can synthesize the field yourself, since your code knows the type at the time of population.
  • If you're getting back a heterogenous list from Apex, you can redesign your server-side controller to return a wrapper class that includes the sObject name with each line item.
  • You can inspect the key prefix (first 3 characters of the Id field) for each record in JavaScript and map that value to an sObject type.
1
  • Thanks for your reply, I was hoping there was some other approach that was a bit more straightforward but seems like not, therefore I have already started to redesign to include wrapper classes with the object name included. I also have an integration to an external system and they don't want dependencies with strict SFDC field names so a wrapper class with agreed field names between both systems will work fine for that purpose as well. Again, thank you..
    – user64485
    Mar 5, 2019 at 22:36
0

The attribute that used in iteration as data-bind must be type Object[]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .