We would like to use a single class for installing our app. To avoid having any more classes than we need, we're trying to consolidate installation into a single class.


public without sharing class InstallationSystem implements Database.Batchable<SObject>, InstallHandler {
    public void onInstall(InstallContext ic) {
        // Initialize some data here
    public Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([some query]);
    public void execute(Database.BatchableContext bc, Sobject[] records) {
    public void finish(Database.BatchableContext bc) {


This code compiles, but will it successfully execute? I'm asking here rather than just dumping it in to our project because I'd like to know if this approach will work, or if I would be better off simply using two classes.

  • 2
    It was a while ago and I don't have the code handy, but I'm fairly sure I've done this and it works. Can't think of any reason it wouldn't, anyway. The only thing you may want to change to be really safe is to replace executeBatch(this) with executeBatch(new InstallationSystem()). Of course you should test this, which wouldn't take much time :) – jkraybill Nov 25 '13 at 22:44

This code compiles, but will it successfully execute?

Yes. BUT:

  1. your Post Install Script runs under a special ghost User that ceases to exist after install is complete.

  2. any Batch Apex kicked off by the Post Install Script will operate under this ghost User,

  3. any records touched by your script or batch apex will be owned or modified by the ghost User,

(The ghost User does have a prefix of 005, and takes its name from the Managed Package. But it doesn't appear in the user list and shows 'Insufficient Privileges' as opposed to the usual 'Data Not Available' if you try to view it. Very elusive!)

ghost user

| improve this answer | |
  • 4
    I found in production, UserInfo.getUserId() gives the 'special ghost user' whereas context.installerId() gives the real initiating user. But in test code, both return the current user! – bigassforce Apr 12 '14 at 15:11

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.