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?

  • So you are executing this code as part of a Post Install Script? Is the code that runs the query in the same file as the Install Script, or is it stored in another file (e.g. in a utility class, or in your scheduled apex class)?
    – zachelrath
    Oct 22 '12 at 16:32
  • 1
    Couple of thoughts. Check if chatter is enabled using something like if (Schema.SObjectType.User.isFeedEnabled()). Secondly check if the Api version of the class running the query is recent so that CollborationGroups are supported? Oct 22 '12 at 17:41
  • @techtrekker - api version is 25 so should be ok. I'm investigating the setup in the orgs where the error occurs to see if anything looks wrong. For reference, if chatter isn't enabled then the package won't install at all. I (presume) then that chatter couldn't be turned off as this code would be present... Oct 23 '12 at 8:11
  • @zachelrath - The code is in a separate utility file called from the postinstall script. Oct 23 '12 at 8:12
  • I got a feeling this has to do with the user profile. Are you sure the user that's executing this code has enough privileges to read CollaborationGroups?
    – rael_kid
    Jan 21 '13 at 7:55

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.

It looks like your querying for Group, as in a user group instead of a Collaboration Group which is the API name for a Chatter group

List<CollaborationGroup> chatterGroups = [SELECT Id FROM CollaborationGroup];


List<Group> groups = [SELECT Id FROM Group];

Try explicitly querying for CollaborationGroup to get the type correct

  • Thx for the comment, already setting the collection 'groups' to be of type CollaborationGroup just didn't add it correctly to the post ;(. Oct 23 '12 at 8:08

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.