I have Added Notes & Attachment in Related List , So when I upload any svg image , It get stored as a file instead of Attachment . So How can we store that image in Attachment instead of contenVersion . My Actually issue is , If file get stored as contentVersion and if other user tries to fetch that file using sql query , Its not returning that record , I tried with adding allUsers to contentDocumnetLink , But still it is not working , So I decided to go with Attachment , As Attachment is accessible to all users . Can you please tell me , How to store image which is uploaded on Added Notes & Attachment button as a attachment
2 Answers
Not sure if I get the question right, but here are some advices.
In general the data model of Files in SF is a bit more complicated than it seems. To get the latest version of a document you should always go trough ContentDocument object to get the latest version using "LatestPublishedVersionId: field, please see the data model and specifications of ContentDocument:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_content.htm https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocument.htm
Salesforce switched to files instead of attachments an year ago. And it is their intention that users use files for storing documents instead of attachments. I would not go against that since all new capabilities would be coming for files and not attachment objects. Also when using SF standard objects it is always good to go with them (their logic and capabilities) this will usually make your life easier in the future.
-
I got your answer to never select Attachment for file . But If I go with ContentVesrion , there will be issue of access , So if I added file then that file will not be visible to other user . Even I worked on ContentDocument to set visibility to allusers inside trigger but still it doesn't work. Commented Dec 22, 2020 at 8:33
-
To share to all users you must create ContentDocumentLink for internal sharing: forcetalks.com/salesforce-topic/… Also there are a few articles on how to do that exactly "It seems in no situations should you have a trigger on ContentDocument. It needs to be on ContentVersion. Something to do with order of operations even though it's less efficient." : developer.salesforce.com/forums/?id=9060G0000005ewuQAA And one last article: trailblazers.salesforce.com/answers?id=9063A000000plqwQAA Commented Dec 22, 2020 at 8:37
-
-
After insert trigger on new ContentDocument object creating ContentDocumentLink objects to all users that you want to share the document see field "LinkedEntityId" and "ContentDocumentId" developer.salesforce.com/docs/atlas.en-us.api.meta/api/… Commented Dec 22, 2020 at 8:48
-
Also take note of the "Visibility" field in the "ContentDocumentLink " specification: developer.salesforce.com/docs/atlas.en-us.api.meta/api/… Commented Dec 22, 2020 at 8:49
In salesforce lightning, the documents will always upload under salesforce files only.
If you want to upload those files in attachments, you can create a custom component to upload the files and store them under the attachments.