Salesforce Fact #859 | NetworkId error in ContentVersion record in test class

Have you encountered the error in test class: You do not have the level of access to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary: [NetworkId]

This error is encountered while trying to insert a ContentVersion record. The insert fails because the NetworkId field is not set.

To resolve this, query the NetworkId from the network Sobject using the below SOQL and set the same in the ContentVersion record before insert:

Id networkId = [SELECT Id FROM Network LIMIT 1].Id;

Reference: https://salesforce.stackexchange.com/questions/325997/insufficient-access-on-cross-reference-entity-networkid

Comments

Popular posts from this blog

Salesforce Fact #192 | Call batch apex from flow

Salesforce Fact #457 | Get current user role name in flow