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.
open developer console and execute following query with your content document Id :
select id from contentVersion where ContentDocumentId = '069xxxxxxxxxxxxxxx'
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 :
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 🙂