0

I'm trying to add "Download" and "Preview" buttons on vf page with the pdf content uploaded to Attachments.

Errors:

  1. How to preview the attachment on same tab for a Preview button on vf page.

  2. Invalid parameter for function URLFOR Error is in expression '{!URLFOR($Action.Attachment.Download, attachmentId)}' in component

VF Page:

<a href="{!URLFOR($Action.Attachment.Download, attachmentId)}" class="btn btn-info">
 <span class="glyphicon glyphicon-save-file"></span> Download
 </a>

Controller:

Public class AttachmentId{
 public string attachmentid {get; set;}

 public AttachmentId(){
 attachmentid='0018000001AcqAX';
   }
 }
1
  • can you clarify, when you say 'tha same tab'... did you try to preview the attachment using Modal/Vustom VF pop-up..?
    – blackwind
    Sep 30, 2016 at 19:22

2 Answers 2

1

Please incorporate following changes:

Visualforce

<apex:page controller="AttachmentClass">
<a href="{!URLFOR($Action.Attachment.Download, attachmentId)}" class="btn btn-info">
 <span class="glyphicon glyphicon-save-file"></span> Download </a>
<br/><br/>
<a href="#" class="btn btn-info" onclick="return window.open('{!URLFOR($Action.Attachment.Download, attachmentId)}','_top');">
<span class="glyphicon glyphicon-save-file"></span> Preview</a>

Apex class

public class AttachmentClass{
public string attachmentid {get; set;}
public AttachmentClass(){
  attachmentid='0018000001AcqAX';
}
} 

I think, your class name and variable name are same, that's the reason behind the error.

1
  • No luck still error exists: invalid parameter for function URLFOR Error is in expression '{!URLFOR($Action.Attachment.Download, attachmentId)}' in component <apex:form> Sep 30, 2016 at 21:09
1

aha, the example Id used by you belongs to account (key prefix 001). try using a attachment or doc id

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .