Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  techtrekker 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... –  Richard Durrant Oct 23 '12 at 8:11
    
@zachelrath - The code is in a separate utility file called from the postinstall script. –  Richard Durrant 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? –  Lex Jan 21 '13 at 7:55

2 Answers 2

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.
share|improve this answer

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];

vs.

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

Try explicitly querying for CollaborationGroup to get the type correct

share|improve this answer
    
Thx for the comment, already setting the collection 'groups' to be of type CollaborationGroup just didn't add it correctly to the post ;(. –  Richard Durrant Oct 23 '12 at 8:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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