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
Sfdc Project 17Sfdc Project 17 

download onclick of commandllink in vf page

I have the ID of contentVersion = 0697F000000lYE0
                         I want to download the file which has this ID , onclick of link
                         <apex:commandLink value="download"/>
                         what should i do to acheive above steps, please help me on this issue.
Best Answer chosen by Sfdc Project 17
Suraj TripathiSuraj Tripathi
Hi,

You Can, Use Outputlink also to get the Id on Vf page 
If you want to download onclick of link.
 
public String converid{get;set;}
public PageReference getContentURL() { 
        
        List<ContentVersion> cv = [select Id from ContentVersion  Limit 1]; 
        if(cv.size()>0)
        {
            converid = cv[0].Id;
            system.debug('----------------converid '+converid);
            return new PageReference('/sfc/servlet.shepherd/version/download/' + cv[0].id);
        }
        else{
            return null;
        }    
    }
 
<apex:outputlink value="{!ContentURL}">Download File</apex:outputlink>
 

I hope this will help you, if it helps you, please don't forget to mark this answer as solved.
Regards 
Suraj

 

All Answers

Suraj TripathiSuraj Tripathi
Hi,

You Can, Use Outputlink also to get the Id on Vf page 
If you want to download onclick of link.
 
public String converid{get;set;}
public PageReference getContentURL() { 
        
        List<ContentVersion> cv = [select Id from ContentVersion  Limit 1]; 
        if(cv.size()>0)
        {
            converid = cv[0].Id;
            system.debug('----------------converid '+converid);
            return new PageReference('/sfc/servlet.shepherd/version/download/' + cv[0].id);
        }
        else{
            return null;
        }    
    }
 
<apex:outputlink value="{!ContentURL}">Download File</apex:outputlink>
 

I hope this will help you, if it helps you, please don't forget to mark this answer as solved.
Regards 
Suraj

 
This was selected as the best answer
Sfdc Project 17Sfdc Project 17
Thankx for respons suraj, it is working now good.