[SalesForce] Receive this error from installed package ‘System.QueryException: sObject type ‘CollaborationGroup’ is not supported.’

I am getting the error –

'System.QueryException: sObject type 'CollaborationGroup' is not supported.'

When running the following code as part of a managed package by scheduled apex:

List groups = [select id, name, description from
collaborationGroup];

What's strange is that the code works if I run it in the developer console but not when it runs from scheduled apex (setup as part of a post install script).

I've got 'with sharing on' so could it be down to the installer user profile? It works in some installed instances but not others but can't see a reason e.g. SFDC edition, profile, chatter settings, etc…

I do know that Chatter has to be enabled but that is the case anyway in the partnerforce dev orgs.

What am I missing here?

Best Answer

Your code must be run in a without sharing context in order for it to have access to the CollaborationGroup SObject. I'm guessing that your Utility class which contains the query is not explicitly declared as without sharing, so you can do one of two things:

  1. Move all of your code into your actual PostInstall Script Apex class (the one that implements InstallHandler).
  2. If possible, change the signature of your Utility class to be without sharing.
  3. Extract out the particular logic that executes this query into a separate Utility class that is declared as without sharing.
Related Topic