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
mjohnson-TICmjohnson-TIC 

Querying ContentDocument Through System Log API Vs Apex Class

Hi All,

 

I've run into an issue where I am able to return results from the ContentDocument object using the system log API but no results are returned from the exact same query I have written in my apex class. Anyone know of any restrictions or ways around this issue?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
mjohnson-TICmjohnson-TIC

I finally figured it out. The apex class I built was api version 20.0. I set it to 23.0 and I can now retrieve the id.

All Answers

EIE50EIE50

Hi,

 

I understand that you are using apex class to return content, may i know where are you displaying it ( i mean site, portal or etc.,.). I am sure it is related to permission issues.

 

Thanks.

mjohnson-TICmjohnson-TIC

I am trying to display the Id of a ContentDocument on a visualforce. The query that throwing an error returning no rows in the apex class is the following.

 

Id ParentId = [Select Id from ContentDocument where Title like 'Monitor1%' LIMIT 1].Id;

 

I as an administrator am the one viewing this visualforce page, and it still retrieves 0 rows and throws the exception.  Running this exact query copied and pasted into the system log api I retrieve 1 row.

EIE50EIE50

Hi,

 

What is that exception message?

 

I assume you have content permissions enabled in your user record.

 

Also, navigate to respective workspace and give yourselves workspace admin permission for time being and then try your apex class.

 

Thanks.

mjohnson-TICmjohnson-TIC

I cant return any contentdocuments through an apex class. Try the following in an apex class and visualforce page.

 

public class with sharing ContentController{

 

public string getdocumentid(){

string documentid = [Select Id from ContentDocument LIMIT 1].Id;

return documentid;

 

}

 

-----------------------

visualforce page 

-----------------------

 

<apex:page controller="ContentController">

<apex:form>

{!documentid}

</apex:form>

</apex:page>

 

You will get the list exception error for returning no rows.

EIE50EIE50

Hi,

 

This works for me,

 

public with sharing class ContentTestCont {
    public String getDocs(){
        String dd = [select id from ContentDocument limit 1].Id;
        return dd;
    }
}

 

<apex:page controller="ContentTestCont">
  <apex:form >
      {!docs}
  </apex:form>
</apex:page>

 Thanks.

mjohnson-TICmjohnson-TIC

I finally figured it out. The apex class I built was api version 20.0. I set it to 23.0 and I can now retrieve the id.

This was selected as the best answer