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
Roshan singh 21Roshan singh 21 

how to show parent related child record in lighting page using Lighting component

how to show parent-related child record in lighting page using Lighting component and also there should be filter functionality like if child record having status filed Status__c.
1. on page load parent-related all child record needs to show 
2. If user select status value equal to Active then all active record need to show.
2. If user select status value equal to Inactive then all inactive record need to show.

Object parent object = Account
Child object = Contract 
Contract object fields:- Name, Status, StartDate__c



I am new to lighting. please help me.
It's very very urgent 
Thanks in Advance. 

ANUTEJANUTEJ (Salesforce Developers) 
Hi Roshan,

>> https://www.sfdckid.com/2019/08/salesforce-lightning-component-to-display-contacts.html

The above link has an example of showing related contacts in the lightning component you can simply replace this with contract soql.

Below is the example for quick reference:
Apex Class-------------------------------------------------
public with sharing class AjinkyaTestLightningAccController 
{
    @AuraEnabled
    public static list<Contact> getRelatedList(Id recordId)
    {
        List<Contact> Conlist = [Select id, name,firstname,lastname from Contact where AccountId=: recordId ];
        return Conlist;
    }
}
Cmp-------------------------------------------------------
<aura:component controller = "AjinkyaTestLightningAccController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="ContactList" type="Contact[]" />
    <aura:handler name="init" value="{!this}" action="{!c.myAction}" />
    <lightning:card iconName="standard:work_capacity_usage" title="Related Contacts">
        <aura:if isTrue="{!not(empty(v.ContactList))}">
            <table class="slds-table slds-table_cell-buffer slds-table_bordered">
                <thead>
                    <tr class="slds-line-height_reset">
                        <th class="slds-text-title_caps" scope="col">
                            <div class="slds-truncate" title="First Name">FirstName</div>
                        </th>
                        <th class="slds-text-title_caps" scope="col">
                            <div class="slds-truncate" title="last Name">LastName</div>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <aura:iteration  items="{!v.ContactList}" var="con">
                        <tr class="slds-hint-parent">
                            <td data-label="File Name">
                                <div class="slds-truncate" title="File Name">{!con.FirstName}</div>  
                            </td>
                            <td data-label="File Name">
                                <div class="slds-truncate" title="File Name">{!con.LastName}</div>  
                            </td>
                        </tr>
                    </aura:iteration>
                </tbody>
            </table>
            <aura:set attribute="else">
                <div Style="text-align : center"> " There are no related contacts "</div>
            </aura:set>
        </aura:if>
    </lightning:card>
</aura:component>
JS------------------------------------------------------
({
myAction : function(component, event, helper) 
    {
        var ConList = component.get("c.getRelatedList");
        ConList.setParams
        ({
            recordId: component.get("v.recordId")
        });
        
        ConList.setCallback(this, function(data) 
                           {
                               component.set("v.ContactList", data.getReturnValue());
                           });
        $A.enqueueAction(ConList);
}
})



Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Soumya Mishra 14Soumya Mishra 14
public with sharing class InlineEditController
{
@Auraenabled
public static list<Inventory_Line_Items__c> getRelatedList(Id recordId)
{
        
List<Inventory_Line_Items_c> Conlist =[ SELECT EPIC_Namec, Use_Case_Namec, Line_Item_Descriptionc, Salesforce_Vlocity_Component_Namec,Complexityc,New_Modifiedc,Unitsc,Adjusterc,Total_Daysc,Total_Hrsc FROM Inventory_Line_Itemsc where Estimator_Detail_c =: recordId];
return Conlist;
}
    
@AuraEnabled
public static void updateRelatedList(List<Inventory_Line_Items__c> Conlist)
     {
          if(Conlist!= null && Conlist.size()>0)
          {
               update Conlist;
          }
         } 
}
plese help   how to wwrite testclass with goverage more than 80%
 
Soumya Mishra 14Soumya Mishra 14
please reply its urgent