function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nello_THnello_TH 

Post install script error

We have a post install script that performs a soql over a custom object that is contained within the managed package. The script is failing on installation with the exception:

 

Install Script Exception

caused by: System.QueryException: sObject type 'NS1__Document__c' is not supported.

 

This apex executes without issue in the development org but fails with the above exception on install... I'm beginning to wonder whether post install scripts support soql over custom objects... Any information on this would be muchly appreciated!

 

Thanks

 

 

sfdcfoxsfdcfox

AFAIK, Post Install scripts don't have access to the org's data, only metadata. I believe the sole except to this is that custom settings are available through the usual CustomSetting.getValues()/getInstance()/getOrgDefaults() functions. The usual use case is to kick off an async call or a batch process that will run after the script terminates. What is your use case for querying in the Post Install script directly?

nello_THnello_TH

Thanks for the information. I have already tried calling a @future method but that resulted in the same exception which suggests it's running within the same context. But maybe kicking off a batch process is different? I'll certainly try it...

 

The use case is this: we have changed the structure of a custom object within a managed package. Data has been moved from exisiting fields in a custom object to now being held in a new child object in a MD relationship. On installation of an upgrade we want to move any existing data in these fields into the new child object fields. We basically want upgrade the database data to be compatible with the upgraded application. So we need to query the parent object and and insert records in the child object.

 

If we can't get the install script working for this case, we'll have to settle for a post install script button in the application somewhere but it's not ideal.

 

Any other thoughts on this, do let me know...

 

Thanks again

sfdcfoxsfdcfox

Try using a batch. It's likely that unless they only had a handful of records, a @future method wouldn't solve anything (remember the 50k limit for query rows). Since you want to update the entire database, a batch would be more appropriate in this use case.