• ShoaebK
  • NEWBIE
  • 0 Points
  • Member since 2016
  • Salesforce Developer
  • Plumlogix.com


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Hi Good People,

I am trying to download an attachment from a command button in Visualforce page. My functionality works fine on records that have an attachment.However, i get "Invalid parameter for function URLFOR

Error is in expression '{!URLFOR($Action.Attachment.Download, attId)}' in component <apex:page> in page mypage"  error on a record that does not have an attachement. How do i get to display this message on records that have no attachment when the Command button is clicked. ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'The document is unavailable!')); instead of getting the above error?

 

Below is part of my controller and Visualforce page that does the download:

public String attId{get;set;}
Candidate__c cand = [Select id,Name,First_Name__c,from Candidate__c where id = :PgId];
Attachment att = [Select id,parentId from Attachment  where parentId = :cand.id];
    if(att != null){
    	attId = att.id;
    	}  
   }  

 

<apex:commandButton action="{!URLFOR($Action.Attachment.Download, attId)}" styleClass="buttonStyle" style="width:100px;height:30px;background:#6699FF;" value="Display Document" rerender="false"/>