[SalesForce] displaying related content in Visualforce page

I am trying to display related content on a custom object within a Visualforce page. I created a custom object and attached a content document to it. I tried doing it using just Visualforce with the <apex:relatedList list="contentDistribution"> tag (as well as some other relatedList options). That does not work. I tried a custom controller extension like so:

public class GVFExtension{
public List<ContentDocumentLink> gvfcontent;
public global_views__c gvfrecord;

public GVFExtension(ApexPages.StandardController stdController){
    this.gvfRecord=(Global_Views__c)stdController.getRecord();
}

public List<ContentDocumentLink> getGVFContent(){

gvfContent=[SELECT ContentDocumentId, ContentDocument.title
            FROM ContentDocumentLink
            WHERE LinkedEntityId=:gvfRecord.Id];
return gvfContent;
}

}

And then my VF page (at least the relevant part):

<apex:pageBlock title="Related Content">
          <apex:PageblockTable value="{!GVFContent}" var="g">
                <apex:column>
                    <apex:outputLink value="/{!g.id}" target="_blank">{!g.ContentDocumentTitle}</apex:outputLink>
                </apex:column>
                <apex:column value="{!g.ContentDocumentId}"/>
            </apex:PageblockTable>
        </apex:pageBlock>

The header for the page block appears, but no related content appears (although I confirm it does appear on standard page layouts). When I look at my debug log it says that the extension was invoked properly but that the relatedRecordId query is using tmpVar1. I'm not sure what I am missing here.

If I can do it using a related list tag, that would be preferable, but all my searching indicates this is not so. I am using API version 33.0.

EDIT: Aha! I found that I should be using ContentDocumentLink, according to new Spring '15 options. Details here. So I updated my code above. The problem is, I still am not getting anything appearing in the Related Content view. The title appears but there is nothing showing.

Best Answer

I've just discovered some odd and saddening idea exchange posts from Alex sutherland about how this isn't possible...

Worked with mpusto earlier today on this. We determined we'd need to use apex to gather the related content in apex and then display. ~30 min of searching has lead to many posts like this one: How to obtain "Related Content" information in SOQL/APEX

Namely that gathering related content from apex isn't possible. Additionally, looking at the ERD (https://www.salesforce.com/developer/docs/api/Content/sforce_api_erd_content.htm#sforce_api_erd_content) and then inspecting those objects, I couldn't find a way to relate a given custom object to related content.

Related Topic