0

On Salesforce standard page for a particular record, all related Notes, Attachments and Files are shown under "Notes & Attachments section".

I have a similar use case where, where on a VF site page:

  1. I am displaying some fields for particular object's record.
  2. Successfully added download option for all related Attachments.
  3. Successfully added download/display option for all related Notes.

However I am not able to display and add download option for related Files.

How to access related files in Apex/VF?

How to add file download link on site page for external user?

Is there any configuration/access permission needs to be granted for site guest user?

1

However I am not able to display and add download option for related Files.

Files are called Content Document, and theier links to record is called ContentDocumentLink. You have to querry the ContentDocumentLink by providing for which record you want those

How to access related files in Apex/VF?

Select id,ContentDocumentId From ContentDocumentLink where LinkedEntityId=:YOUR_RECORD_ID

How to add file download link on site page for external user? If the internal user has made that file as public accessible, then the file link will be stored in contentDistribution.

Select Id, DistributionPublicUrl  FROM ContentDistribution WHERE ContentDocumentId = contentDocumentID

DistributionPublicUrl is the public URL for that file.

Src: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdocumentlink.htm

https://developer.salesforce.com/forums/?id=906F0000000g1ClIAI

  • Hi Pranay, Thanks for your inputs! I tried same SOQL from anonymous window/workbench (with admin profile), then it is returning me result list. However, for some reason, when I tried same SOQL in site page's controller, then it is returning empty list. Also i tried same URL but in return it is showing error 'top.location={{instance}}/ex/errorduringprocessing.jsp'. Is there any configuration/access issue for site guest user? – sfdcnoob Nov 29 '18 at 18:00
  • Can you make your apex class as without sharing? – Pranay Jaiswal Nov 29 '18 at 18:02
  • Yes! controller is already without sharing. SOQL still returning empty list – sfdcnoob Nov 29 '18 at 18:04
  • Hi Pranay, Regarding "DistributionPublicUrl -- ContentDistribution", as per my observations and some other answers references [salesforce.stackexchange.com/questions/1625/…, we are not able to create "ContentDistribution" or "ContentDielivery" programmatically. It only gets created when you manually created and share public link, – sfdcnoob Nov 29 '18 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.