Hey guys, today in this post we are going to learn about How to query related list to use lookup relationship for display the contact record into lead object based on record Id in Salesforce.
The Related Record List component shows, in a list, a single type of record related to a record. For example, if you’re looking at an Lead, you can see a related list of Lead for that Contact. Use the Related Record List component on a generic Related Record List page or on a custom page. Members can create records from the list and from lookups.
When a user expands the list of related records, the Related Record List page is displayed, which uses the Related Record List component under the hood. The component may occasionally be empty. For example, if there aren’t any records related to the current record, or if the current record was created in the last 24 hours, no related items populate the component.
The Related List – Single component shows a list of related records based on one specific object. For example, if you’re looking at a contact detail page, you can specify to see the lead related to that contact, without seeing all other types of related records. Use the Related List – Single component on an object page or on a custom page to add specific, related information in context for the page. Members can create records from the list and from lookups. To know more details about Related List, Click Here.
Files we used to display related list record in Lightning Component→
leadContactCmp.cmp | Lightning Component | It is used for create a table for display the related list record from child to Parent |
leadContactCmpController.js | JavaScript Controller File | It is hold Javascript doInit and navigate functionality to navigate on sObject record. |
leadContactCmpHelper.js | JavaScript Controller Helper File | It is hold for Javascript Helper Function Communicate to Related Queries Values (Child to Parent) from apex method |
leadContactCtrl.apxc | Apex Class Controller | It is used for get SOQL query from Child to Parent from Apex Method |
Final Output →
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
- Find the below steps ▾
Create Lightning Component →
Step 1:- Create Lightning Component : leadContactCmp.cmp
From Developer Console >> File >> New >> leadContactCmp.cmp
leadContactCmp.cmp [Lightning Component File]
<aura:component controller="leadContactCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="conList" type="List[]"/>
<div class="slds">
<table class="slds-table slds-table--bordered">
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.conList}" var="conItem">
<tr>
<td>{!conItem.Contact__r.Name}</td>
<td>{!conItem.Contact__r.Phone}</td>
<td>{!conItem.Contact__r.Email}</td>
<td>{!conItem.Contact__r.Description}</td>
</tr>
</aura:iteration>
</tbody>
</table>
</div>
</aura:component>
Create JavaScript Controller →
Step 2:- Create Lightning Component : leadContactCmpController.js
From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller
leadContactCmpController.js [JavaScript Controller]
({
doInit:function(component,event,helper){
helper.getContactList(component,event,helper);
},
})
Create JavaScript Helper →
Step 3:- Create Lightning Component : leadContactCmpHelper.js
From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper
leadContactCmpHelper.js [JavaScript Helper File]
({
getContactList : function(component,event,helper) {
var action = component.get("c.leadContactList");
action.setParams({
"recordId":component.get("v.recordId")
});
action.setCallback(this,function(response){
var state = response.getState();
if(state=='SUCCESS'){
var result = response.getReturnValue();
component.set("v.conList",result);
}
});
$A.enqueueAction(action);
},
})
Create Apex Class Controller →
Step 4:- Create Apex Class : leadContactCtrl.apxc
From Developer Console >> File >> New >> Apex Class
leadContactCtrl.apxc [Apex Class Controller]
public class leadContactCtrl {
@AuraEnabled
public static List<Lead> leadContactList(String recordId){
List<Lead> leadList = [SELECT Id, Contact__c, Contact__r.Name, Contact__r.FirstName, Contact__r.LastName, Contact__r.Email, Contact__r.Phone, Contact__r.Description FROM Lead WHERE id=:recordId];
//system.debug('leadList ' + leadList);
RETURN leadList;
}
}
Further post that would you like to learn in Salesforce
What is related record ID in Salesforce?
Each record in the Salesforce.com system has a unique ID field assigned to it which is known as Record ID. It is system generated and cannot be edited or deleted. It is generated every time a new record is inserted into the application.
What are related records in Salesforce?
The Related Record component is a standard Lightning Page component linked to a quick action. It displays information on a related record and allows users to edit, create and associate other records.
How do you display related records in lightning component?
First, edit the lightning page layout by clicking on the setup gear in the upper right-hand corner and selecting Edit Page. Add a related record component by dragging it from the component list to the page. Choose which record is displayed by clicking Edit Lookup Fields and choosing contact name and then done.
Related Topics | You May Also Like
Our Free Courses →
👉 Get Free Course →
📌 Salesforce Administrators 📌 Salesforce Lightning Flow Builder 📌 Salesforce Record Trigger Flow Builder |
👉 Get Free Course →
📌 Aura Lightning Framework 📌 Lightning Web Component (LWC) 📌 Rest APIs Integration |