1

See:

Why does adding a Queueable cause an INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY error?

for some background. That results in the need to set the NetworkId (there is one of these per Community) on the ContentVersion object.

Passing that Id explicitly can be awkward, and given the NetworkMember object, a query:

select NetworkId from NetworkMember where select MemberId = :UserInfo.getUserId()

will return the zero or more relevant NetworkIds.

In my experience, a Username is unique to a Community, meaning the above would return the required single NetworkId. But are there other Community setups where the same UserId applies to more than one Community?

Keith C
  • 135,775
  • 26
  • 201
  • 437

2 Answers2

1

Yes, NetworkMember solves the problem of which users are part of a given Community/Experience.

However it is technically possible to add the same profiles, permission sets, and users on multiple communities, but that gets very messy.

So, probably the best is to keep it separate. I have worked on deploying multiple communities under the same org but back then they used separate profiles, but I don't know the usage in the wild.

Jeferson Chaves
  • 2,482
  • 1
  • 10
  • 26
1

I checked in my current org as we do assign users to multiple communities and the query below

select NetworkId 
from NetworkMember 
where select MemberId = :UserInfo.getUserId()

Returns a row for each community the user is associated with.

As mentioned by @JeffersonChaves, adding members to your community is as simple as adding their profile or permission set to have access to it. This means a given user, based on their profile and/or permission set, could be a member of multiple communities. Whether this is common, I do not know - but, it is possible and have seen this setup in multiple orgs.

Based on that info, you'll either have to add another filter to specify the community you're interested in by passing the Community name to your queueable/code:

select NetworkId 
from NetworkMember 
where select MemberId = :UserInfo.getUserId() AND Network.Name = :communityName

Or stick with passing in the NetworkId to use in the query.

Kris Goncalves
  • 22,133
  • 8
  • 33
  • 68