We have a managed package and wants to check if the subscriber has enabled Network object in their Org. I try with this Schema.sObjectType.Network.isAccessible() But getting an error if the network object is not enabled.

Error: "Missing Organization Feature: NetworksEnabledOnce"


The moment you use a "static reference" to a feature, it becomes a dependency. In other words, your code depends upon Communities being enabled, and therefore the platform requires it to be enabled.

Code like the following automatically causes dependency:

Map<String, SObjectField> fieldMap = Schema.sobjectType.Network.fields.getMap();
Network[] records = [SELECT Name FROM Network];
Network record = new Network(Name='abc');

In order to avoid this, you will need to use "dynamic references", such as the following:

if(Schema.getGlobalDescribe().containsKey('Network')) {
  sobject[] results = Database.query('select name from network');
  for(sobject result: results) {
    String name = (String)result.get('Name');
    // ... etc ... //

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.