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 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();
        cg.name = '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
add comment

1 Answer 1

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

context.installerId()

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(
            Name='Lorem',
            Description='Lorem Ipsum',
            CollaborationType='Private',
            OwnerId=context.installerId()
        );
        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
add comment

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.