Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a CollaborationGroup when a managed package is installed. Currently I get an error 'INVALID_CROSS_REFERENCE_KEY, This user can't be added to the group.: []' when I run the following in a postInstall Script

     CollaborationGroup cg = new CollaborationGroup(); = 'Lorem';
        cg.description = 'Lorem Ipsum';
        cg.collaborationType = 'Private';

        insert cg;

I believe this is due to the special user context the postinstall script runs under as the code works fine if run normally. Any way around this?

share|improve this question

The short answer is not you can not run as a proper user. But you can get the Id of the user who initiated the install using


My suggestion for you Chatter Group problem would be to try and set the OwnerId of the CollaborationGroup e.g

global class PostInstallClass implements InstallHandler {
    global void onInstall(InstallContext context) {
        CollaborationGroup cg = new CollaborationGroup(
            Description='Lorem Ipsum',
        insert cg;

Disclaimer: I have not tested this so I don't know if it will work for sure.

share|improve this answer
Seems like this has also failed. Same error so guessing that the 'special user' is still being added as a member of the collaboration group even if the owner id is set. I've moved all of this outside of the postinstall and have created a page that finishes off the installation via an actionLink. Old Skool ways can still be the best ;) – Richard Durrant Nov 15 '12 at 10:27
Damn that is frustrating, you might consider logging a case with salesforce so they fix it (or won't) – Daniel Blackhall Nov 15 '12 at 20:45

Your Answer


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.