0

I have a custom object that links to "Contact" and would like to display the list of all related records of the custom object in the "Contact" list view. Is this possible?

So if I had, for example:

CustObj1 -> Contact1
CustObj2 -> Contact1
CustObj3 -> Contact1
CustObj4 -> Contact2

I would like to see on the Contacts tab for each Contact:

Contact1   |   CustObj1.Name, CustObj2.Name, CustObj3.Name |
Contact2   |   CustObj4.Name |
| improve this question | | | | |
1

If you do not want to use a custom Visualforce page, you could add a field on the Contact called "Related CustObjs" and assign to it using an Apex Trigger on the CustObj__c:

Trigger relatedObjsTrigger on CustObj__c (after insert, after update)
{
    Set<ID> contacts = new set<ID>();
    for(sObject i : trigger.New)
    {
        CustObj__c obj = (CustObj__c)i;
        if (obj.Contact__c != null)
        {
            contacts.add(obj.Contact__c);
        }
    }
    Map<ID, Contact> contactMap = new Map<ID, Contact>([select ID, Related_CustObjs__r from Contact where ID in :contacts]);
    for(sObject i : trigger.New)
    {
        CustObj__c obj = (CustObj__c)i;
        List<String> relatedObjs = contactMap.get(obj.Contact__c).Related_CustObjs__r.split(', ');
        relatedObjs.add(obj.Name);
        relatedObjs.sort();
        contactMap.get(obj.Contact__c).Related_CustObjs__r = String.join(relatedObjs, ', ');
     }
     update contactMap.values();
}

Note that this code does not remove the custom object from another contact's list if the related contact is changed, I'll leave that as an exercise for the reader. Based on this thread, if the field is a rich text field you can even add hyperlinks to the records by inserting '<a href="' + obj.ID + '">' + obj.Name + '</a>' instead.

| improve this answer | | | | |
0

you can build look up relation or master detail relation with that custom object and you can find the child record in related list. otherwise if you are trying to show it in Visualforce Page then you can use below code : -

<apex:page standardController="Contact">
    <apex:relatedList list="CustomObject__r"/>
</apex:page>
| improve this answer | | | | |
0

It looks like this can't be done out of the box, but there is a good (and free) AppExchange app that does what I want: https://github.com/afawcett/declarative-lookup-rollup-summaries

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.