Access Latest Attachment from List View and View it

  • 1
  • Question
  • Updated 4 years ago
  • Answered
I have a list of Contacts and I'd like to be able to access their latest attachment via the list view.

(of course I think if I can make a URL on the contact detail itself I can also access this from the list view... maybe using a formula field?  This would be aweseome)

When clicking on this link or row action, it would be great if we can either, open a new tab with the latest document, do a pop up, or even better a scroll over view.  Really anything will suffice.

I found this online which allows me to create a button and utilize JavaScript.  https://success.salesforce.com/answers?id=90630000000hQ6jAAE

This is great on the Contacts detail record, but again I am trying to do this from a list view.

I'm guessing it is as easy as having a URL redirect to this.

<A Href = "/servlet/servlet.FileDownload?file={{{Id}}}"; Target = "_Blank"> {{Name}} </A>

Or setting up a pop up 

<iframe src="/servlet/servlet.FileDownload?file={{{Id}}}" style="width:100%; min-height:650px;"></iframe>

BUT.... how I get the most recent attachment ID from this Contact... that is a bit confusing because I can't really traverse the model from the list view.
Photo of Kramer Keller

Kramer Keller

  • 330 Points 250 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
In your models - fields properties you will notice a "child relationships" section.  This is where you add the attachment relationship fields to your model.  You can also specify filters on the child data,  sort order and number of rows returned.  I'd reccomend order by createdDate DESC  and only show one record. 

Then you drag that child relationship item from the field list down into your table and it acts like a template component,  where you define a custom label and use syntax that looks like this.  

<A Href = "/servlet/servlet.FileDownload?file={{{Id}}}"; Target = "_Blank"> {{Name}} </A>

This will do what you are looking for. 
Photo of Kramer Keller

Kramer Keller

  • 330 Points 250 badge 2x thumb
Rob, Awesome.  I don't think I have messed with the child relationships yet.  I am going to find some new uses now!  Everything worked, but I did need to put {{Title}} instead of {{Name}}.  When I did {{Name}} nothing happened.