I am trying to get the image addresses from Salesforce Files using the following query in workbench. There are thousand files, but no results are displaying.

Select Id, ContentDocumentId, ContentDownloadUrl, DistributionPublicUrl 
from ContentDistribution 
where ContentDocumentId='0691000000FOq3nAAX'`

The result I would like to achieve is the address a user gets each time he/she right-clicks an image and click the Copy Image Address option.

Would appreciate if someone could help me with this inquiry.


Did you create ContentDistribution for those files? Well, like ContentDocument, ContentDistribution isn't created when a file is added or its ContentVersion is created. Either you create it manually for the file, or it'll be created when you click on Public link under Salesforce files.

So please try the following code,

ContentVersion cv = [Select Id From ContentVersion Where ContentDocumentId = '0691000000FOq3nAAX'];
ContentDistribution cd = new ContentDistribution();
cd.contentVersionId = cv.Id;
cd.Name = cv.Title;

Now you can query on ContentDistribution and it'll give the public access link and download link to your file.

ContentDistribution cDis = [Select Id, ContentDocumentId, ContentDownloadUrl, DistributionPublicUrl 
from ContentDistribution 
where ContentDocumentId='0691000000FOq3nAAX'];
| improve this answer | |
  • Thanks for letting me know. I don't know that this is the behavior. I thought links are available in default when files are uploaded in Salesforce. Upon checking, Public Link option does not display for image files. But it shows on other formats though (pptx, pdf, docx). – Ertyq May 18 at 4:30

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.