3

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.

  • have you tried getting rid of the "rendered ..." tag? Also, the "header" column can't display any data, there's no "value" tag there. – Jagular Apr 28 '15 at 15:13
  • Also, if contentdistribution is a related list then you would want <apex:relatedList list="contentDistribution__r"> (note the "__r"). More here ->blog.jeffdouglas.com/2009/05/13/… – Jagular Apr 28 '15 at 15:25
  • Even with the __r, does not work. Also took out the render tag. No dice – mpusto Apr 28 '15 at 15:31
  • Is ContentDistribution a standard object? I can't see it my my org. – Jagular Apr 28 '15 at 15:44
  • It's standard if Content is enabled. – mpusto Apr 28 '15 at 15:47
1

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.

|improve this answer|||||
1

One option I've tried (suggested by greenstork privately) was to use <apex:detail> with relatedList="true". This works if I strip out all the unnecessary fields from a page layout, but then I get back to the Salesforce look/feel for the name of the object, which is less than ideal. But surprise! My client actually thought it was ok in this case. So props to greenstork for directing me that way.

|improve this answer|||||
0

Are you sure that you are using the correct Child Relationship Name? On your child object, navigate to the lookup field on the child object and look at the Child Relationship Name, that is the value plus __r that you want in your list attribute.

enter image description here

In this example, the related list tag would be Donations__r

|improve this answer|||||
  • The related Content seems to be a special case. There is no way for me to look at the child object, as it is the related content. I used the Developer Console to look at the ContentDistribution object, as well as the other Content objects. I was thinking ContentDistribution due to this post: developer.salesforce.com/forums?id=906F0000000AvgRIAS – mpusto Apr 28 '15 at 15:32
  • Try RelatedRecord or RelatedRecords – greenstork Apr 28 '15 at 15:39

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.