0

I have written custom VF page on CASE object to show custom object as related list to the CASE. I could able to do that but I need to show at the top of all other CASE's standard related list. Im only trying to show ObjA's related list at the top of case standard related list. if you see the below picture .. it's a override case custom VIEW page... I'm trying to bring that Obj A at the bottom to top of Time Trackings related list..

Extension

public class Relatedlist {
    Private List<ObJ_A__c> obja;
    private Case cse;
    public RelatedList(ApexPages.StandardController controller) {
        this.cse = (Case)controller.getRecord();
    }
    Public List<Obj_A__c> getObjA() {
        Case cse = [Select id, Contact.id, CaseNumber from Case WHERE id = : cse.id];
        if(cse.Contact == null) return null;
        obja = [Select Name, User__c, XXXX__c, XXXX__c, from Obj_A__c WHERE User__c = :cse.Contact.id];
        return obja;
    }
}

Page

<apex:page standardController="Case" extensions="Relatedlist" sidebar="true">
    <style>
    .fewerMore { display: none;}
    </style>
    <apex:tabPanel selectedTab="Knowledge"> </apex:tabPanel>
    <chatter:feedWithFollowers entityId="{!Case.Id}" />
    <apex:form >
        <apex:pageMessages > </apex:pageMessages>
        <apex:detail relatedList="true" inlineEdit="true" > </apex:detail>  
        <apex:pageblock id="CustomList"  title="ObjA"  >
            <apex:pageBlockTable value="{!obja}" var="l" rendered="{!NOT(ISNULL(obja))}">
                <apex:column value="{!l.Name}"/>
                <apex:column value="{!l.User__c}"/>
                <apex:column value="{!l.XXXXXX__c}"/>                                   
                </apex:pageBlockTable>
                <apex:outputLabel value="No records to display" rendered="{!(ISNULL(lcnse))}" styleClass="noRowsHeader"></apex:outputLabel>
            </apex:pageblock>                             
    </apex:form>                                                        
</apex:page>

Screenshot

Page Screenshot

4
  • 3
    This is a bit unclear, showing more context would be helpful
    – cropredy
    Commented Apr 28, 2016 at 15:47
  • @Gidy If you are querying for the list objA you can just modify your SOQL to add an ORDER BY clause.
    – Adrian Larson
    Commented Apr 28, 2016 at 15:49
  • If you want to move the apex-created related list CustomList ahead of the related lists defined in the page Layout (because you are using apex:detail relatedList="true" , you're going to need jQuery to manipulate the DOM after page load.
    – cropredy
    Commented Apr 28, 2016 at 16:08
  • 1
    @Gidy For future reference, please edit your post when you have content to add, instead of tossing it in the comments
    – Adrian Larson
    Commented Apr 28, 2016 at 16:13

2 Answers 2

1

If you want to keep apex:detail, two options, neither pretty:

Option 1

Requires jQuery DOM manipulation, you'll need to hack into the VF page using Firebug or its ilk to see the structure and use jQuery methods to move a DOM tag (and its children) representing your custom RL ahead of the DOM tag for the first OOB related list. This is certainly doable as I have done this before swapping pageBlockSections around based on data values.

Option 1 has issues:

  1. It has to work for both inline edit and otherwise
  2. It is fragile as it depends on how SFDC renders into DOM the related lists
  3. It has to be tested for Lightning as well as Classic

Option 2

Don't use the OOB related lists on apex:detail but instead do:

<apex:detail relatedList="false" ...>
<your custom related list goes here>
<apex:relatedList ... list for RL 1>
<apex:relatedList ... list for RL 2>
<apex:relatedList ... list for RL 3>

Option 2 has all sorts of issues:

  1. Not all OOB related lists can be shown - notably field history. You then need to use a custom component (Google it) for the field history RL. Some relatedLists even have bugs in them like ServiceContracts
  2. You lose the quick links / mini hovers normally seen at the top of apex:detail. Reconstructing them requires javascript hacks to call internal SFDC javascript methods

So, you end up with a more complex page that is also semi-fragile if you try to reproduce the quick links/mini-hovers

0

If you want to reorder the records in the list

You need to modify this line in your extension:

obja = [
    SELECT Name, User__c, XXXX__c, XXXX__c
    FROM Obj_A__c WHERE User__c = :cse.Contact.id
];

You have some confusing naming, what with a User__c lookup matching a ContactId, but that's beside the point. You need to add an ORDER BY clause. Here is one example:

SELECT Name FROM Obj_A__c WHERE User__c = cse.ContactId ORDER BY Name DESC

If you want the list above the detail

To place the list above the entire detail view, you just need to reorder the tags.

<apex:pageBlock>
    ...
</apex:pageBlock>
<apex:detail />

If you want to insert the list between Case History and Related Cases

What you want to accomplish is not possible, and if you find a way it's going to involve some serious hacking.

7
  • Adrian - I think OP wants his custom apex-related list to appear before the apex:detail - generated related lists when viewed from top to bottom
    – cropredy
    Commented Apr 28, 2016 at 16:43
  • @cropredy Ah, upon rereading it looks like he wants it in between related lists on the detail. Not possible then.
    – Adrian Larson
    Commented Apr 28, 2016 at 16:44
  • 1
    well, possible with jQuery DOM rearranging after page load; I've done this before (kind of) by rearranging pageblocksections and I don't see why it couldn't be done (fragile, yes, subject-to-sfdc-breakage, yes) here.
    – cropredy
    Commented Apr 28, 2016 at 16:46
  • @cropredy But isn't the detail inside an iframe? Can you really move the DOM in that way?
    – Adrian Larson
    Commented Apr 28, 2016 at 16:50
  • 1
    @Gidy -- as I thought - solution requires jQuery DOM manipulation, you'll need to hack into the VF page using Firebug or its ilk to see the structure and figure out how to move a DOM tag (and its children) representing your custom RL ahead of the DOM tag for the first OOB related list
    – cropredy
    Commented Apr 29, 2016 at 14:18

Not the answer you're looking for? Browse other questions tagged .