dispaly_image from file salesforce

Formula Fields to Display Images From Files/Content Documents – Salesforce Lightning/Classic

Admin Configuration

Welcome back guys, Today in this post we are going to learn, how we can create custom formula field to display images from salesforce files or content documents (ContentVersion) object

Step 1: Obtain the File (Content Version) image file record Id.

After upload your image/Picture as file, open your file object | click on view file details

next, copy Content Document Id from URL which is started from 069xxxxxxxxxxxxxxx

now we have content document/File id, next we will fetch the contentVersion Id with this content document Id.

Check also : How To Display Lightning Component In Visualforce Page-Sample

open developer console and execute following query with your content document Id :

select id from contentVersion where ContentDocumentId = '069xxxxxxxxxxxxxxx'
Note : Update your content document ID in SOQL Query

   Now, finally we got our image file (content Version) Id which has starting from 068xxxxxxxxxxxxxxx. copy it. we will use this Id in our formula field.

Step 2 : Create a new “Text” type Formula Field :

In Salesforce Classic Mode :

1. Go to Setup | Customize | <Object> — Select the Object you are going to customize (Accounts, Case, Opportunity).
2. Click Fields.
3. Under “Custom Fields,” click New.
4. Select Formula.
5. Click Next.
6. Enter your custom field name, then select Text from the “Type” picklist.
7. Click Next.
8. In the “Enter Formula” screen, click Advanced Formula and use following formula.

IMAGE("/sfc/servlet.shepherd/version/download/0686F000004UD7T", 'image alternate text',240,320)

update your content version id in above formula and click on next and then save.

In this post for the demo purpose i have used hard code Id in formula, you can create a custom field to store file id and use that field in formula to make it dynamic.

now open any record detail page to see output :

Some Useful Resources : 

Check Also : Customize Salesforce logIn Screen In Just Few Minutes

Like our facebook page for new post updates. & Don’t forget to bookmark this site for your future reference.

if you have any suggestions or issue with it, you can post in comment box  or Developer Forums 🙂


  • Hello sir

    I used to learn a lot of thing from your blog.

    I have a query that if I have 10 records with some fields and a custom field that show the related image. I want to retrieve all those images in a lightning component then how can it possible??

  • Hi how to create a link of the uploaded file in the custom field?

    I have created a formula field using this hyperlink

    HYPERLINK(“#/ContentDocument/0690E000000Qfy1QAC/view?fv0=” &CORE_Tech_File_Link__c, “_self”)

    but its throwing an error : No syntax errors in merge fields or functions. (Compiled size: 156 characters)

    Also I want to make this hyperlink as dynamic.

    Really appreciate your help.!!

  • Hi,

    I followed all the steps and tested them in a sandbox. Everything worked great. Now the situation is I need to recreate the exact same thing for about 19,000 images :'( After converting the attachments to files, the images that were visible through a Visualforce page are now just files and all users are unable to view.

    How can I reference all the images in a formula without being just specific to one? TIA

Leave a Reply