+ Start a Discussion

How to Query a File uploaded to Article through SFDC in Visual force using SOQL



      I extended the Article Type object and Added a Field of type File. Filed name is Files_to_attach__c. I trield to Access the Field in SOQL as Follows 

Select b.Files_to_attach__c,b.Author__c,b.ArticleNumber,b.Title,b.status__c from Book__kav b
                                where PublishStatus = 'Online' and Id =:ApexPages.currentPage().getParameters().get('id') ; 


But I got an Error :

ErrorError: ArticleDetailsController Compile Error: No such column 'Files_to_attach__c' on entity 'Book__kav'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 101 column 31. 


After that I found the File Field has subfields Files_to_attach__Name__s (type is Text)

Files_to_attach__ContentType__s (type is picklist)

Files_to_attach__Length__s (type Number 9,0)

Files_to_attach__Body__s (type Text area).


     SOQL allowing to query the subfields . I want to know How to retrieve the File id for the Field Files_to_attach__Name__s so that when Im clicking on the File name I can down load the File.


Please share with me if any other approaches are available.


Thanks in Advance.






I have a similar requirement too in order to retrieve the attachments from Article ? Were you able to get any answer for your query?




If you want to access file field from a VF page, the syntax is not obvious but documented ;). 




If your article type has a File field, you can allow users to download the field's content. In the following example, the article type is Offer, the name of the File field is my_file, and the text that appears as a link is Click me:


<apex:outputLink value="{!URLFOR($Action.Offer__kav.FileFieldDownload,  Offer__kav.id, ['field'=$ObjectType.Offer__kav.fields.my_file__Body__s.name])}">Click me</apex:outputLink>