6

I have a VisualForce page where I'm trying to display a standard related list by using the <apex:relatedList /> tag. It seems like this should be simple, but I can't seem to find any way to choose which columns are displayed in the related list; the only column being displayed is the "Name" column.

I've tried editing the related list layout on the custom object's page layout, but this didn't affect my VisualForce page.

Is there any way I can display more than just the "Name" column with an <apex:relatedList />?

3
  • 1
    Did you change the related list layout ON the Page Layout that your profile sees based on the record type of the record you are viewing?
    – Eric
    Commented Aug 11, 2014 at 19:23
  • I did add it to the layout, however it looks like my profile did not have view permission for the fields, so even though they were on the page layout, they did not appear in the related list. Adding view permission to my profile fixed the issue Commented Aug 11, 2014 at 19:34
  • Do you mind converting it to an answer then? It'll make the question go "off the radar" and improve our stats of unanswered questions... and I'd happily upvote it :)
    – eyescream
    Commented Aug 11, 2014 at 21:50

2 Answers 2

6

Content of <apex:relatedList> will match what your user would see for same record on standard page layout. So your best choice is to configure the list on page layout. Remember that if you still don't see the fields you expect, the standard caveats apply:

  • do you have rights to read on the fields from the related list?
  • if the fields are lookups - do you have at least "Read" right to the referenced object
  • (licensed package fields) do you have have a licence associated to your user
  • (page layout assignment depends on Profile and optionally on Record Type) are you sure you've modified the right page layout for your combination?
5
  • Is it possible to specify the columns to display in a related list w/o using an extension? The requirement is the standard page layout has 7 columns in the related list and am creating a mini page where I need to show only 3 columns. I like to use the related list as it has capabilities like limiting to only 5 records on initial load. So the question is can I show just 3 columns instead of all the 7?
    – DCBoy
    Commented Aug 12, 2014 at 10:26
  • 1
    @DCBoy apex:repeat, dataTable, pageBlockTable etc all have rows attribute which you can use to limit them. So I guess you could roll out your own rel. list (as a component maybe?), with your own columns (taken from fieldset?)... Maybe even add a link to view more (could navigate to real related list's "See All" page but also could navigate to current VF page with value of {!$CurrentPage.parameters.pageSize} doubled for example)
    – eyescream
    Commented Aug 12, 2014 at 10:38
  • Thanks @eyescream, was hoping to do it with just the relatedlist component but guess custom is the way to go. Appreciate the response.
    – DCBoy
    Commented Aug 12, 2014 at 10:48
  • the help doc salesforce.com/us/developer/docs/pages/Content/… talks about using facet:body to customize the look and feel of the records so wondering if this is the answer to pick the columns we want. But I couldn't find a way to reference the record being iterated over, have any thoughts here?
    – DCBoy
    Commented Aug 13, 2014 at 0:28
  • @DCBoy No idea. Probably good old object.Relationship instead of passing just the Id and waiting for magic to query automatically... {!Account.Contacts}, {Custom_Parent__c.Custom_Children__r} etc.
    – eyescream
    Commented Aug 13, 2014 at 6:05
1

My requirement was to have related lists on custom VF page and embed the VF on Page layout. So this is how I achieved it:

The columns shown in "apex:relatedList" is controlled by: 1) Related list setup if the corresponding related list exists in the page layout. Having the same related list again on page layout doesnt make any sense though. So I hid it. And then I found the second way as follows:

2) If related list is not added to page layout, then by Tab Layout of the custom object. If you have not created the tab for that object, then you will see the name only. So create Tab, edit Tab layout to have all desired columns and there you have it.

You must log in to answer this question.

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