4

I have a requirement to download multiple files on a click of visual force button.

i know below will work if its a single file

<a href="/servlet/servlet.FileDownload?file={!Documents}">

any clue about how to gain this for multiple files

4

There is no way standard way to achieve this goal. Apex Code doesn't have native "compressed file" APIs, so you can't compress the files together easily. HTML doesn't have a specification that allows a single link to represent multiple resources simultaneously. HTTP doesn't have a specification that allows a single request to serve multiple files without assistance from the browser (e.g. when resource X explicitly loads resource Y), and even if there were, Visualforce doesn't allow us to use arbitrary headers that we would need to support this logic. This leaves you with a couple of choices: 1) you could email the files to the recipient, 2) you could try to emit a ZIP file, or 3) you could try to concatenate the files into a ZIP file and provide a link to that resource. If email is a viable choice, you can use the interface provided by Apex Code for this. As for the others, they are non-trivial tasks, and I would probably skip trying them at all.

  • 1
    what about this one,salesforce.com/us/developer/docs/ajax/Content/… looping it for multiple files – sfdc99999 Nov 25 '13 at 10:20
  • 1
    You could try that, but it isn't as straight-forward as you think. For one, JavaScript is slow and still largely browser dependent. Using HTML5 on latest browsers, you would have a better chance. Unfortunately, there's no "write api", so you'd still have to download the files to the browser, process them, upload them back to the server, then download the resulting compressed file. Is this worth it? Maybe, if the files are small and your network and computer is fast. OTOH, you could use a signed Java applet for saving files directly to the drive. This requires extra work, too. – sfdcfox Nov 25 '13 at 11:40
  • hmm ie true..how about this blog valnavjo.com/blog/compressing-files-in-salesforce sorry i am not an expert in apex.was just trying to find different options and see how experts like you comment on it – sfdc99999 Nov 25 '13 at 12:51
  • also files in consideration is chatterfiles. – sfdc99999 Nov 25 '13 at 14:48
0

It will work if you want download selected document

function downloadFile() {
        var arrayOfLinks =[]
        j$('#downloadSelected .num ').each(function(i,val){
            var checkbox_cell_is_checked = j$(this).closest('tr').find('input').is(':checked');
            if(checkbox_cell_is_checked){
                arrayOfLinks.push(j$(this).text());
             }
        });
downloadAll(arrayOfLinks);
 }
function downloadAll(files){
        //alert('Inside'+files.length);
        if(files.length>0){
            var file = files.pop();
            //alert('Inside'+files.length);
            window.open(file, 'Download');
            setTimeout(downloadAll, 1500, files);
 }
}
  • 1
    Welcome to SFSE Srikanth! This answer is what is called a "code dump". You've provided code, but no explanation as to how it works, or how it solves the problem that OP (the Original Poster of the question) is experiencing. Such answers are usually low-quality, and have a tendency to spawn a lot of "that didn't work" and "try this instead" in the comments. High-quality answers tend to explain what the problem is, why it is a problem, how to fix it, and why your fix works. Doing that makes an answer valuable to other people experiencing similar issues too. – Derek F Jul 24 '18 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.