[SalesForce] Query ContentVersion with Community User
I have a simple question. Can users with Customer Community Login query the ContentVersion object?
Best Answer
Yes the users with Customer Community can query ContentVersion records
String communityId=Network.getNetworkId();//Use community Id to figure logged in Users Current Community
SELECT Id,
FileType,
SystemModstamp,Title, ContentUrl,ContentDocumentId,ContentDocument.LatestPublishedVersionId, PathOnClient, VersionData from contentVersion WHERE OwnerId =: UserInfo.getUserId() and NetworkId=: communityId order By CreatedDate DESC
Users (including users with the “View All Data” permission) can only
query files they have access to, including:
All Salesforce CRM Content files in libraries they're a member of and in their personal library, regardless of library permissions
(API version 17.0 and later).
All Chatter files they own, posted on their profile, posted on groups they can see, and shared directly with them (API version
21.0 and later).
The only value that gets updated in the Apex instance for any SObject when you insert is the Id value. Other fields populated as part of the insert by triggers or other logic have to be re-queried to get the values - ContentVersion is no different.
Quite a lot can go on behind the scenes for ContentVersion, including the automatic addition of a ContentDocumentLink to the User who inserted the version.
I've found ContentNote/ContentDocument/ContentVersion/ContentDocumentLink quite awkward to work with compared to e.g. just a Note.
Best Answer
Yes the users with Customer Community can query ContentVersion records