function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bohemianguy100bohemianguy100 

Query Salesforce Content object

Is it possible to query the Salesforce Content object?  I have a need to build a vf page that allows the user to view content records and attach content to a specific contact record.

 

I'm currently trying to query the ContentVersion object and I'm not getting an error, but no content is getting displayed.  I have added one piece of content and am simply trying to return that record in my query.

 

Thanks for any help!

Best Answer chosen by Admin (Salesforce Developers) 
ericmonteericmonte

What information are your trying to retrieve?

 

Here is a sample VF page i have and here is the controller

<apex:page controller="ContentVersionAlt">
    <apex:form >
        <apex:pageBlock >

            <apex:repeat value="{!contentVersions}" var="cv">
                <apex:pageBlockSection title="Title {!cv.Title} {!cv.id}" >
                    <apex:outputText >Title: <a href="/{!cv.id}">{!cv.title}</a> </apex:outputText>
                    <apex:outputText >Description: {!cv.description} </apex:outputText>
                    <apex:outputText >FileType: {!cv.FileType} </apex:outputText>
                    <apex:outputText >Author: {!cv.Owner.Name}</apex:outputText>
                    <apex:outputText >Revision:  {!cv.VersionNumber}</apex:outputText>
                    <apex:outputText > Document Id: {!cv.ContentDocumentId}</apex:outputText> 
                
                </apex:pageBlockSection>
            </apex:repeat>
            

        </apex:pageBlock>
        
    </apex:form>

     
</apex:page>

 

public class ContentVersionAlt {

    public List<ContentVersion> getContentVersions() {
          return [select id, Title, Description, FileType,
           Owner.Name, VersionNumber, ContentDocumentId from ContentVersion
           Where IsLatest = true];
       }
}

 Let me know if this helps you or if you have questions let me know

All Answers

ericmonteericmonte

What information are your trying to retrieve?

 

Here is a sample VF page i have and here is the controller

<apex:page controller="ContentVersionAlt">
    <apex:form >
        <apex:pageBlock >

            <apex:repeat value="{!contentVersions}" var="cv">
                <apex:pageBlockSection title="Title {!cv.Title} {!cv.id}" >
                    <apex:outputText >Title: <a href="/{!cv.id}">{!cv.title}</a> </apex:outputText>
                    <apex:outputText >Description: {!cv.description} </apex:outputText>
                    <apex:outputText >FileType: {!cv.FileType} </apex:outputText>
                    <apex:outputText >Author: {!cv.Owner.Name}</apex:outputText>
                    <apex:outputText >Revision:  {!cv.VersionNumber}</apex:outputText>
                    <apex:outputText > Document Id: {!cv.ContentDocumentId}</apex:outputText> 
                
                </apex:pageBlockSection>
            </apex:repeat>
            

        </apex:pageBlock>
        
    </apex:form>

     
</apex:page>

 

public class ContentVersionAlt {

    public List<ContentVersion> getContentVersions() {
          return [select id, Title, Description, FileType,
           Owner.Name, VersionNumber, ContentDocumentId from ContentVersion
           Where IsLatest = true];
       }
}

 Let me know if this helps you or if you have questions let me know

This was selected as the best answer
bohemianguy100bohemianguy100

Thanks Eric!  It appears to be a permission issue.  I'm a system admin and I have selected "Salesforce CRM Content User" checkbox on my user record as well.

 

I was able to add a piece of content to my Personal Library and then I was able to successfully query that record.  Do I have to be added as a member to other libraries in order to query the content? 

ericmonteericmonte

Honestly, I am not sure, but based on my experience on working with content recently you have be a memeber.