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
Renee EllisRenee Ellis 

Show related records of a custom object on a detail page for that custom object


I have a custom object with a master detail relationship to the Contact object. 

I would like to have, on the custom object's record detail page, a list of all other records for that custom object's record that are related to the linked contact. 
Like a related list, but for records on the same object, not a child object.

I found a way to show a related list for another object linked to the contact, but not on the same object
<apex:page standardcontroller="app__c">
<apex:relatedList subject="{!app__c.Contact__c}" list="apps"/>

Org is still in Classic

You need standard controller and extension both.

VF code:-
<apex:page standardcontroller="app__c" extensions="showAppRecords">
<apex:repeat var ="r" value="{!records}">
Exentsion :-
public class showAppRecords{

public List<app__c> records{get;set;}

public showAppRecords(StandardController con){
string appId=ApexPages.currentPage().getParameters().get('id');
records=[Select id, name from app__c where Contact__c =:appId ];

Hope this works.

Ajay K DubediAjay K Dubedi
Hi Renee,

Below Code can fulfill your requirements, Hope this will work for you.
Vf page :

<apex:page standardController="app__c" extensions="ShowRelatedrecord">
    <apex:form >
       <apex:pageBlock >
         <apex:pageBlockSection >
            <apex:pageBlockTable value="{!appLst}" var="app">
              <apex:column value="{!}"/>        

Class :

public with sharing class ShowRelatedrecord {
    public list<app__c> appLst{get;set;}
    public ShowRelatedrecord(ApexPages.StandardController controller) {
            appLst = new list<app__c>();
            appLst = [Select id, name from app__c where Contact__c =: ApexPages.currentPage().getParameters().get('id')];


Please mark this as best answer if this solves your problem.

Thank you,
Ajay Dubedi
Renee EllisRenee Ellis

Hi Ashishk, unfortunately that solution didn't work, I go errors on line 5 of the extension.

Hi Ajay, thank you, that solution provided the block with table containing header. However no records listed. 

any ideas?