[SalesForce] Create a ContentVersion document available for all users

Sorry if this seems easy, but I am new to Salesforce…

What I did so far is:

  • Query files using apex
  • Do operations according to VersionData of queried files

Everything works as expected. However, when a different user triggers the operation to fetch the files, he can not access my library. How can I create the files so that all users can access them or how can I access higher level users library?

Thanks in advance!

File creation:

ContentVersion contentVersion_1 = new ContentVersion(
        Title = 'some title',
        PathOnClient = 'some title'+'.txt',
        VersionData = Blob.valueOf('some content to access later on'),
       IsMajorVersion = false /*so that can be updated later on*/
    );
insert contentVersion_1;

File Querying:

List<ContentVersion> jsonFiles=[select Title, VersionData from ContentVersion where Title='some title'];

Best Answer

I've seen this issue before. I solved it by changing the FirstPublishLocationId (described here) to a public folder:

FirstPublishLocationId
Type: reference
Properties: Create, Filter, Group, Nillable, Sort
Description : ID of the location where the version was first published. If the version is first published into a user's personal library or My Files, the field will contain the ID of the user who owns the personal library or My Files. If the first version is published into a public library, the field will contain the ID of that library.

If this is truly to be a public folder you can probably create a new public folder using this documentation. If not you can also modify the folder to be accessible to a sub set of users by user id, or by profile.

Click Create New Folder or Edit from most pages that list folders.
1. Enter a Folder Label. The label is used to refer to the folder on user interface pages.
2. If you have the “Customize Application” permission, enter a unique name to be used by the API and managed packages. 3. Choose a Public Folder Access option. Select read/write if you want users to be able to change the folder contents. A read-only folder can be visible to users but they can't change its contents.
4.Select an unfiled report, dashboard, or template and click Add to store it in the new folder. Skip this step for document folders.
5. Choose a folder visibility option:
- This folder is accessible by all users, including portal users gives folder access to all users in your organization, including portal users.
- This folder is accessible by all users, except for portal users gives folder access to all users in your organization, but denies access to portal users. This option is only available for report and dashboard folders in organizations with a partner portal or Customer Portal enabled. If you don't have a portal, you won't see it.
- This folder is hidden from all users makes the folder private.
- This folder is accessible only by the following users allows you to grant access to a desired set of users

Related Topic