I need to get the URL to view an attachment in Apex. In Visualforce, I can use URLFOR($Action.Attachment.Download, a.id). In this case, I want to return a PageReference from an Apex method that sends the user over to the view attachment page.
I can manually build the link as '/servlet/servlet.FileDownload?file=' + a.Id , but I'd rather not hardcode that.
I tried using URL.getFileFieldURL(a.Id, 'Body')
but I'm getting an error: Invalid parameter value "Body" for parameter "fieldName". The example looks like it is used on an Idea record (prefix 087). Maybe it doesn't work on Attachment records.