function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ahmed AbdelhamedAhmed Abdelhamed 

Display Master-Detail custom object records in Lightning.?

please an full example
NagendraNagendra (Salesforce Developers) 
Hi Ahmed,

You need to create a component that is specifically for your detail object. It takes an attribute that is the master items ID. Place this component inside the master item component.
<c:ListDetailItems masterItemId="{!v.masterItem.Id}"/>
Pass the detailItem List and masterItemId into the c:detailItem to be iterated over.
//c:ListDetailItems 

<aura:component controller="ListWBItemsActivitiesApexController">
    <aura:attribute name="masterItemId" type="String"/>
    <aura:attribute name="detailItems" type="detail[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    

    <aura:iteration items="{!v.detailItems}" var="detailItem"> 
    <c:detailItem detailItem="{!detailItem}" masterItemId="{!v.masterItemId}"/>
    </aura:iteration>
</aura:component>
You then create a getSubItems function that executes in the doIt. Since you now have the master item Id, you can use that in your function call on the client and the server.
//client controller for c:ListDetailITems
getDetailItems : function(component) {
		var action = component.get("c.getDetailItemsDB");
   		var masterItemId = component.get('v.masterItemId');
    	action.setParams({ "masterItemId" : masterItemId});
    	action.setCallback(this, function(response) {
        var state = response.getState();
        if(component.isValid() && state == "SUCCESS") {
            component.set("v.detailItems", response.getReturnValue());
        }
    });
    $A.enqueueAction(action);
},
//Apex server controller

public with sharing class ListDetailItemsApexController {
    @AuraEnabled
    public static List<detailItem> getDetailItemsDB(String masterItemId) {
        return [SELECT Id, IsDeleted, Name, 

                 //other fields for your SOQL
                FROM detailItem
				WHERE masterItem =: masterItemId];
    }
}
Hope this will help you with the above issue.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra



 
Ahmed AbdelhamedAhmed Abdelhamed
can you please also write the <c:detailItem detailItem="{!detailItem}" masterItemId="{!v.masterItemId}"/>  Component?