+ Start a Discussion
SarisfdcSarisfdc 

Calculate number of downloads

Hi,

I have attachments in my records and i have given link of the arttachmet on VF page to download the attached file in the record.
I want to calculate number of times attached file in attachment is downloaded.

Please help!

Thanks
Sari
pconpcon
I don't know of a native way to do this.  You may be able to track it with something like Event Monitoring [1] but that cost an additional fee and would require you to pull the data externally and then write it to the record.

Another option woud be to create a Visualforce Page that is blank except for an action on the load of the page.  That action then reads the Id from the page URL, incements the download count on the record and redirects to the attachment directly.  This would require that anywhere you want to count the attachment download, you have to link to that Visualforce page.  This may not work because there are restrictions as to when you can do DML operations, and I do not remember if a page level action is one of those.

A third option would be to write Javascript on your page that you are displaying the download link and update the record onclick there.  This may present problems if you have a large user group that runs different browsers and having to be compatible with them.  Also, the asyncronous nature of this type of call may lend itself to increase chances of encountering locking issue.

[1] https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/using_resources_event_log_files.htm