Find your content:

Search form

You are here

Post Install Script - Is it possible to run as a proper user?


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?

Attribution to: Richard Durrant

Possible Suggestion/Solution #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


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.

Attribution to: Daniel Blackhall
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content