function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
camelUsercamelUser 

Question about files home

When uploading a document either by the API or form the ui i notice that it is only accessable by the user who uploaded it, i can see that form the UI atleast i can share with indevidual user so that they can also access it.

is there a method to share the document with all users?

is there a method to share the document from the API?
- make it avalibe via a file 'Related list' on an opportunity?
Best Answer chosen by camelUser
Raj VakatiRaj Vakati
You need to set Visibility and ShareType  and Visibility  
Refer this link 

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdocumentlink.htm
​​​​​​​
ShareType
Required. The permission granted to the user of the shared file in a library. This is determined by the permission the user already has in the library. This field is available in API version 25.0 and later.
V
Viewer permission. The user can explicitly view but not edit the shared file.
C
Collaborator permission. The user can explicitly view and edit the shared file.
I
Inferred permission. The user’s permission is determined by the related record. For shares with a library, this is defined by the permissions the user has in that library.

Visibility  
Specifies whether this file is available to all users, internal users, or shared users. This field is available in API version 26.0 and later.
Visibility can have the following values.
AllUsers—The file is available to all users who have permission to see the file.
InternalUsers—The file is available only to internal users who have permission to see the file.
SharedUsers—The file is available to all users who can see the feed to which the file is posted. SharedUsers is used only for files shared with users, and is available only when an org has private org-wide sharing on by default. The SharedUsers value is available in API version 32.0 and later.

 

All Answers

Vivek DVivek D
Every File is has a ContentDocumentLink reord/records linked to it. Based on which the sharing is set in Salesforce. 
ContentDocumentLink dL = new ContentDocumentLink();

// I means Inferred based on the related object
dL.ShareType = 'I';
// Visibility AllUsers etc 
dL.Visibility = 'AllUsers';
// related document
dL.ContentDocumentId = id;
// related record Id
dL.LinkedEntityId = id;
Raj VakatiRaj Vakati
You need to set Visibility and ShareType  and Visibility  
Refer this link 

https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_contentdocumentlink.htm
​​​​​​​
ShareType
Required. The permission granted to the user of the shared file in a library. This is determined by the permission the user already has in the library. This field is available in API version 25.0 and later.
V
Viewer permission. The user can explicitly view but not edit the shared file.
C
Collaborator permission. The user can explicitly view and edit the shared file.
I
Inferred permission. The user’s permission is determined by the related record. For shares with a library, this is defined by the permissions the user has in that library.

Visibility  
Specifies whether this file is available to all users, internal users, or shared users. This field is available in API version 26.0 and later.
Visibility can have the following values.
AllUsers—The file is available to all users who have permission to see the file.
InternalUsers—The file is available only to internal users who have permission to see the file.
SharedUsers—The file is available to all users who can see the feed to which the file is posted. SharedUsers is used only for files shared with users, and is available only when an org has private org-wide sharing on by default. The SharedUsers value is available in API version 32.0 and later.

 
This was selected as the best answer