You need to sign in to do that
Don't have an account?

Help with Invalid parameter for function URLFOR on Empty Notes & Attachment
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"/>
I would change the page so that if there are no attachments, the button is not rendered. I think you may also need to defend against more than one attachment for a record. Something like:
All Answers
I would change the page so that if there are no attachments, the button is not rendered. I think you may also need to defend against more than one attachment for a record. Something like:
Thanks Bob, that did it :-)
VF Code
Apex Code
Bob, i'm having this error for the above mentioned code.
Error: Error occurred while loading a Visualforce page.
Error: Invalid parameter for function URLFOR