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
Shailender GuptaShailender Gupta 

How to download multiple Attachment using {!URLFOR($Action.Attachment.Download, Id)}?

Best Answer chosen by Shailender Gupta
Deepak Kumar ShyoranDeepak Kumar Shyoran
As this URLFOR takes Id as a parameter for the Attachement you want to download. So if you can pass Id dynamically for all the attachment you want to download ... like by using  {!URLFOR($Action.Attachment.Download, Id)} inside a loop which open these link repeadly. You can acheive this by using apex:repeat and javascript.

//listOfAttacmentI is a list of Id having all attachment you want to download.

<apex:repeat value="{!listOfAttacmentI} var="attachId" >
<script>
window.open('{!URLFOR($Action.Attachment.Download, attachId)}','_blank') ;
<script>
</apex:repeat>
Hope above code will help you. Please modify it according to your need.

Please mark my answer as a best solution to your question to help others if it solves your problem.

All Answers

Deepak Kumar ShyoranDeepak Kumar Shyoran
As this URLFOR takes Id as a parameter for the Attachement you want to download. So if you can pass Id dynamically for all the attachment you want to download ... like by using  {!URLFOR($Action.Attachment.Download, Id)} inside a loop which open these link repeadly. You can acheive this by using apex:repeat and javascript.

//listOfAttacmentI is a list of Id having all attachment you want to download.

<apex:repeat value="{!listOfAttacmentI} var="attachId" >
<script>
window.open('{!URLFOR($Action.Attachment.Download, attachId)}','_blank') ;
<script>
</apex:repeat>
Hope above code will help you. Please modify it according to your need.

Please mark my answer as a best solution to your question to help others if it solves your problem.
This was selected as the best answer
Shailender GuptaShailender Gupta
Deepak Kumar Shyoran
i am using above code inside button
<apex:commandButton value="download" title="download"  rerender="tab">
                       <apex:outputPanel id="tab">
                         <apex:repeat value="{!a}" var="attachId" >
                            <script>
                           window.open('{!URLFOR($Action.Attachment.Download, attachId)}','_blank') ;
                            </script>
                         
                          </apex:repeat>
                          </apex:outputPanel>
  </apex:commandButton>

but its not working there
Deepak Kumar ShyoranDeepak Kumar Shyoran
Are you getting any error or how it's not working for you ? As tried the above code and it's working for me. The above code will open all your attachment associated with {!a} in a new link from there you can download them.
Please check your POP allocation Option for the browser.