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
Anil KamisettyAnil Kamisetty 

Identify CRUD Privileges on Files in Apex

Attachments are being replaced by FILES and everyone is encouraged to use FILES going forward. Files can be added to any record and at the same times, User can post files to Chatter. Also there is a concept of Private Files (Accessible by the Owner or Creator).

What is the best method to check if the User has access to Create / Update / Delete a File in Apex ?

Colloboration might help for files in a folder but not for Personal Files. What is the best method to address this in Apex ?
PrasathPrasath
Hi Anil,

You can achieve this scenario using IsPrivate field
Type
boolean
Properties
Create, Defaulted on create, Filter, Group, Sort, Update
Description
Indicates whether this record is viewable only by the owner and administrators (true) or viewable by all otherwise-allowed users (false). During a create or update call, it is possible to mark an Attachment record as private even if you are not the owner. This can result in a situation in which you can no longer access the record that you just inserted or updated. Label is Private.
Attachments on tasks or events can't be marked private.
Anil KamisettyAnil Kamisetty
IsPrivate is available on very few objects, Opportunity / Attachment / Note / Event & NoteandAttachment. Not available on File.

If the OwnerID on the ContentDocument matches with the User, probably need to call is PRIVATE file or there exists only one ContentDocumentLink for the File (i.e. for the created or Owner). File becomes shared if there exists an additional CONTENTDOCUMENTLINK created.