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
Jay reddyJay reddy 

Custom object as a related list to Case Object

Hi Everyone,

I have requirement based on the below conditions.

3 objects [Case, Contact, CustomObj]

Contact and CustomObj have lookup relationship.... and case is created based on contact.

My requirement is CustomObj appears as a related list in CONTACT record... I need bring that same CustomOBJ related list to CASE records whenever that particular CONTACT is added or CASE created on that CONTACT.... How can I achieve this.. I tried to edit layout but no luck it is not showing as related list instead appear in Extended lookup area...
Best Answer chosen by Jay reddy
Kay AndersonKay Anderson
You could pull the related list with visual force and add it to the layout, something like this:

<apex:page showHeader="true" sidebar="true" standardController="Case">
    <apex:relatedList subject="{!Case.Contact}" list="CustomObjs__r" />
</apex:page>

Or you could add a lookup to the Case on your CustomObj and auto populate it using either apex or a flow.

All Answers

Kay AndersonKay Anderson
You could pull the related list with visual force and add it to the layout, something like this:

<apex:page showHeader="true" sidebar="true" standardController="Case">
    <apex:relatedList subject="{!Case.Contact}" list="CustomObjs__r" />
</apex:page>

Or you could add a lookup to the Case on your CustomObj and auto populate it using either apex or a flow.
This was selected as the best answer
piyush sfpiyush sf
Hi,
  As per my understanding, there s no relationship between case and custom object. So following approach needs to be take :
  1. Create a lookup and relate case to the custom object using trigger.
  2. Visualforce page if no relation between case and custom object is required.
  
Thanks
Piyush
sfpiyush@gmail.com
Jay reddyJay reddy
Hi Kay Anderson, piyush,

I don't see the Visualforce page in the edit pagelayout

User-added image

 
Kay AndersonKay Anderson
Scroll down and you will see a Visualforce Pages choice in your list on the left.  Remember to grant access to the VF Page on your profiles (that catches me all the time).
Jay reddyJay reddy
Hello Kay,

Thanks for the idea!! It worked but I have one more thing to ask ... I have added the custom related list with your idea... Now I would like to place it on the top of the Standard Related list... Could you please let me know the way??

<apex:page>
-----------
<apex:detail relatedList="true" inlineEdit="true" > </apex:detail>  
                            <apex:pageblock id="CustomList"  title="Licensee"  >
                                <apex:pageBlockTable value="{!lcnse}" var="l" rendered="{!NOT(ISNULL(lcnse))}">
                                    <apex:column value="{!l.Name}"/>
                                    <apex:column value="{!l.User__c}"/>
                                    <apex:column value="{!l.ProductName__c}"/>
                                    <apex:column value="{!l.State__c}"/>
                                    <apex:column value="{!l.EndDate__c}"/>
                                    <apex:column value="{!l.Support__c}" />
                                 </apex:pageBlockTable>
                                 <apex:outputLabel value="No records to display" rendered="{!(ISNULL(lcnse))}" styleClass="noRowsHeader"></apex:outputLabel>
                             </apex:pageblock>                             
                          </apex:form>  
                          
                         <!-- <apex:relatedList list="Cases"/>
                          <apex:relatedList list="Comments"/>
                            <apex:relatedList list="ActivityHistories"/>
                          <apex:relatedList list="CombinedAttachments"/>
                          <apex:relatedList list="Time_Trackings__r" />
                          <apex:relatedList list="Case" subject="{!Articles}" /> -->                                    
                      </apex:page>

Bascially, I tried to do by <apex:detail relatedList="false" inlineEdit="true" > </apex:detail> and gave the standard related list as below.. but for Emails, Case Comments, Articles etc it's throwing error as Emails/CaseComments/... are/is not a valid child relationship name for entity Case.
Kay AndersonKay Anderson
Girish,
     I don't know, I just put the list at the bottom of my page layout.  If you find an answer please share, I'd love to know!