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
calvin_nrcalvin_nr 

Link to a document in the Documents folder not working in VF page

I am trying to display a link on a custom VF page to a word document which has been uploaded to a folder in the Documents tab.

 

For some reason this is not working as expected. The link is not pointing to the document. Security is also not an issue. I am not doing something right in the VF I suppose.

 

Here is my controller code:

 

public with sharing class osv_portal_HomePageContoller {
public string strDocUrl;
public osv_portal_HomePageContoller()

{

    try
    {
        List<Document> lstDocument = [Select Name from Document where Name = 'SLA-Technology' limit 1];
        string strOrgId = UserInfo.getOrganizationId();
        strDocUrl = '/servlet/servlet.FileDownload?file='+lstDocument[0].Id;

    }
    catch (Exception e) 
    {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Error in getDocumentLogoUrl() ' + e.getMessage()));
        System.debug('Error: ' + e.getMessage());
    }
        System.debug('The URL is ' + strDocUrl);
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'The URL returned is ' + strDocUrl));   

    }

 This is my VF code:

<apex:outputLink value="{!strDocUrl}" id="theLink" styleclass="slabutton">
    <span class="delete">Service Level Agreement</span>
 </apex:outputLink>

Thanks,
Calvin

Jia HuJia Hu
You code works for me.
Check your debug log to see if you can find the errors, since you will handle the error by yourself.

And make sure your SOQL query does find some document.
calvin_nrcalvin_nr

^^I have made these checks my friend.

 

The problem I think is the user type. The portal user is a High volume user. When I log in with my account(Im a system admin). I can access the document. The portal user has security to view the doucment but somehow for some reason, the link is blank for him.