2

I've two thing for Communities & No-Communities.

1 - To post a Feed to a User in Communities - https://help.salesforce.com/apex/HTViewSolution?id=000187667&language=en_US This works fine for Community User & Non-Community User.

FeedItem post = new FeedItem(ParentId = UserInfo.getUserId(), CreatedById = thanks.GiverId, Body = thanks.Message, RelatedRecordId = thanks.Id, Type = 'RypplePost');

        String networkId = Network.getNetworkId();
        if(networkId != null) {
            post.NetworkScope = networkId;
        }

        insert post;

This works fine in Communities, but breaks when Communities are not enabled. If I comment out 'post.NetworkScope = networkId;' - the package installs fine, if not I get the Installation Error as below:

2 - Images in Community How to include images from static resources in lightning components used in communities?

String networkId = Network.getNetworkId();

if(networkId != null) {
 List<Network> networks = [ Select UrlPathPrefix from Network where Id = :networkId ];
 if(networks.size() > 0) {
   return '/' + networks[0].UrlPathPrefix;
 }
}
return '';

I'm appending that UrlPathPrefix to the Images on communities when UrlPathPrefix != ''. I think Select UrlPathPrefix from Network where Id = :networkId is causing the below error.

  1. Missing Organization Feature: Networks null

  2. Missing Organization Feature: NetworksEnabledOnce null

Thanks.

1

I think the issue is because even to use Network class ,the Network Object should be available in the org .Also it depends if your class is using with sharing or without sharing .

With sharing means the package installation context will obey the installing user privileges else it will be a ghost user .

You can follow below methodology to make sure communities is enabled for all community related logic

Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
if(gd.containsKey('Network')){
   system.debug('Communities is enabled!');
  return true;
}else{
  system.debug('Communities is disabled!');
  return false;
}
  • Thanks for the answer, but No, it did not work :( Missing Organization Feature: NetworksEnabledOnce – Surya Chandra Rao Gandreddi Jul 29 '16 at 5:12
  • List<Network> networks = [ Select UrlPathPrefix from Network where Id = :networkId ]; Gives this error: sObject type 'Network' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. – Surya Chandra Rao Gandreddi Jul 29 '16 at 5:17
  • post.NetworkScope = Network.getNetworkId(); - Gives this error : Missing Organization Feature: Networks – Surya Chandra Rao Gandreddi Jul 29 '16 at 6:48

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.