I have code that inserts a ContentVersion (a File) that is run under a "Customer Community Login" license inside a Community/Experience. That works fine.

I now have an optional asynchronous layer that wraps that code in a Queueable that is started via a System.enqueueJob. This version fails with:

INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.: [NetworkId]

At first I thought this Queueable apex invoked from triggers doesn't inherit sharing correctly might be the cause but changing the Queueable to be without sharing did not fix the problem as I hoped it might.

Any ideas anyone?

1 Answer 1


It is because you need to send the NetworkId. Network.getNetworkId returns null during queuable invocation.

So, it is necessary to pass around or query the NetworkId as soon as you introduce async indirection.

See this code for reference: ConvertAttachmentsToFilesService: it contains an instance to hold the value of NetworkId given the queuable context looses it.

This caused a big refactor for this library based on their Issue #9.

  • 1
    Yes from a quick test of hard-coding the Network Id this looks like the problem. So it is not only the sharing context that is lost across the async calls but this Network Id too. In the multiple package code I work on, this is going to be painful to address.
    – Keith C
    Commented Mar 9, 2021 at 19:33
  • Agreed, one solution for us might be to query NetworkMember on that scenario, but this still ugly, but the flip side is that you can avoid packaging multiple packages (at least not required any sort of global). Commented Mar 9, 2021 at 21:46
  • 1
    Thanks for all your help here Jeferson.
    – Keith C
    Commented Mar 10, 2021 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .