[SalesForce] Managed package install script – sObject type not supported

I have a managed package with a PostInstall script, however I'm having trouble accessing custom objects within it.

Apon installation, I get the following error notification email

System.QueryException: sObject type 'mypackage__Settings__c' is not supported.

The line referenced in the exception is a normal SOQL query against a custom object in the package

Settings__c = [SELECT Field1__c, Field2__c FROM Settings__c LIMIT 1;

Is there any reason why I shouldn't be able to access custom objects in the PostInstall script? It appears to work in other places.

Best Answer

Does your post install script have with sharing in the class definition?

If it does, try removing it or changing to without sharing. There may be an issue with the user that the post install script is running as not being able to access the custom object when sharing rules are enforced.

Related Topic