I keep getting the PostScript Failed for the managed package we are testing. When I try and run I get an 'Attempt to de-reference a null object' on context (Line 3) but I am not sure how. Pulled this from the Developer guide and didn't change much just to make sure that I could start with something working but I am running into an error 'Error Message: The post install script failed.' Am I missing something in our code?

global class PostInstallClass implements InstallHandler {
 global void onInstall(InstallContext context) {
 if(context.previousVersion() == null) {
  Workspace__c ww = new Workspace__c();
  if(context.previousVersion().compareTo(new Version(1,0)) == 0) {

if(context.isUpgrade()) {

if(context.isPush()) {

  • You haven't created any InstallHander/InstallContext classes/interfaces yourself, have you? What do you mean by "When... I run..."? Do you mean when you install the package? Do you get the same problem without doing the insert? Oct 15, 2023 at 15:44
  • If I don’t have the install class and we install the package we have no errors. If I run the package in the dev instance it seems to fail on I’m assuming the context part. Is there another item we need to create for context? Oct 15, 2023 at 16:41
  • No. What do you mean by "run the package"? Do you mean "install the package"? As long as you don't install the package, you don't have an InstallContext. During installation you can't easily see what's going wrong (I'm therefore surprised you're sure the culprit is line 3). I'd rather suspect that the insert fails. Maybe build a global exception handler and send yourself an email with the stack trace?! Oct 15, 2023 at 17:08
  • To put it in cut and dry steps.. when I run the install handler code in our dev instance I get an error on line 3 which is why I was asking. If I install the package into a production instance I just get an error massage of the post script failed. I will try and send myself an email to find out if there is an error message. I was more coming to this community to see if there was any helpful advice. Oct 15, 2023 at 17:21

1 Answer 1


You can test install script only on the real push upgrades / installations of your managed package. In the Developer console, on the dx orgs etc. InstallContext context equals null.

To prevent your code from failing, add check on null:

if (context != null) {
    // your current code goes here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .