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
Ruhi Bell 5Ruhi Bell 5 

sObject type 'ApexClass' is not supported

I work on a managed package which has a scheduled Apex job that runs daily. This job includes some code that gets our managed package namespace prefix and prepends it to our custom objects. For some reason when an organization has our managed package installed the scheduled job fails with the following error.

Failed to process batch for class 'kimbia_sync.DeleteKimbiaLogs' for job id '7071a00002zBrzq'
caused by: System.QueryException: sObject type 'ApexClass' is not supported.

I can run the same code in that org through the developer console and it works just fine. 

I found this issue on StackExchange (https://salesforce.stackexchange.com/questions/27113/invalid-type-sobject-type-apexclass-is-not-supported) but it's a few years old and the API Access feature is now deprecated. I opened a Salesforce support ticket asking if they could help out and they checked one of the affected orgs and it had the correct setting so I'm at a loss. 
D-CoderD-Coder
Add "Without Sharing" keyword on class. This will resolve the problem.