+ Start a Discussion
Christian LinenkoChristian Linenko 

Show related content on a Case Visualforce page

I have a VF page where I'm looking to display related content on it. From the documentation I found (https://www.salesforce.com/developer/docs/api/Content/sforce_api_objects_contentdocumentlink.htm), you need to query the ContentDocumentLink object. Here's what my code looks like:

String eyeDee = Apexpages.currentPage().getParameters().get('Id');
thisCase = [SELECT Id, IsClosed, Subject FROM Case WHERE Id =: eyeDee LIMIT 1];
for(ContentDocumentLink c: [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId =: thisCase.Id])
            kIds.add(c.ContentDocumentId);
content = [SELECT Id, Title, Description, Owner.Name, CreatedDate FROM ContentVersion WHERE PublishStatus = 'P' AND IsLatest = true AND ContentDocumentId IN: kIds ORDER By CreatedDate];

When I load the page however, I don't get any results. 

On the standard page (https://www.dropbox.com/s/fov495yzhyelami/Screenshot%202015-01-19%2012.46.15.png?dl=0) I can see the content. On the VF page, I don't get anything.

VF Code:
<apex:pageBlock title="Related Content">
   <apex:pageBlockTable value="{!Content}" var="c" rendered="{!Content.size != 0}">
      <apex:column >
          <apex:facet name="header">
               Title
          </apex:facet>
          <apex:outputLink value="/customers/{!c.Id}" target="_blank">{!c.Title}</apex:outputLink>
      </apex:column>
      <apex:column value="{!c.Description}"/>
      <apex:column value="{!c.Owner.Name}"/>
      <apex:column value="{!c.CreatedDate}"/>
   </apex:pageBlockTable>
   <apex:outputText value="No Content Related" rendered="{!Content.size == 0}"/>
</apex:pageBlock>

Any help would be awesome.
Best Answer chosen by Christian Linenko
Marty C.Marty C.
Hey, Christian, I think for the Related Content list on the Case object, you want to query ContentDistribution instead of ContentDocumentLink. Would you give the following query a try instead?

 
SELECT ContentDocumentId, ContentVersionId
FROM ContentDistribution
WHERE RelatedRecordId =: thisCase.Id

 

All Answers

Marty C.Marty C.
Hey, Christian, can you upload a screenshot of the standard related list you mentioned in your question?
Christian LinenkoChristian Linenko
Here's the records on the non VF page.

Records on standard page.
Christian LinenkoChristian Linenko
No records on the VF page.

No records on the VF page.
Marty C.Marty C.
Hey, Christian, I think for the Related Content list on the Case object, you want to query ContentDistribution instead of ContentDocumentLink. Would you give the following query a try instead?

 
SELECT ContentDocumentId, ContentVersionId
FROM ContentDistribution
WHERE RelatedRecordId =: thisCase.Id

 
This was selected as the best answer
Christian LinenkoChristian Linenko
@Marty, tried that. Getting this error: sObject type 'ContentDistribution' is not supported.
Marty C.Marty C.
Can you try changing the API version of your Apex class to 32.0 (Winter '15)?
Christian LinenkoChristian Linenko
@Marty, that did it. Thanks so much for your help.
Christian LinenkoChristian Linenko
@Marty, that did it. Thanks so much for your help.