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

ERROR: System.QueryException: sObject type 'Organization' is not supported


We have a specialized rollup class (GW_OppRollups) that is initiated from a trigger and batch. The class aggregates opportunity data either to a contact, linked through the primary contact role or an account listed on the opportunity. Since we're dealing with opportunity data aggregation, it's important for us to summarize the data by the fiscal year. To get the fiscal year, we must query the Organization object in the constructor of our class. 

The class lives in a managed package, and the code for that class can be found here:

The class if failing on line 107, with the query of the organization object with the error:
Apex script unhandled trigger exception by user/organization: 005A0000002DdCX/00DA0000000Ak04

GWBase.GW_OpportunityTriggerAfter: execution of AfterInsert

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

Class.GWBase.GW_OppRollups.<init>: line 107, column 1
Trigger.GWBase.GW_OpportunityTriggerAfter: line 40, column 1 

The problem is that the class shouldn't be failing. The class, GW_OppRollups operates in system context, does not have With Sharing turned on, and therefore should be able to freely query the Organization object regardless of which user initiates the class call from a trigger. Do I have this wrong? Is there any other way to query the fiscal year start month?

Any help appreciated, thanks in advance. I've filed a case with support


Salesforce Case #07274301



I would test this out by explicitly stating without sharing on the class level, first test this out and let us know the results....


Also the sharing rule can change dynamicly depending on what calls your class...


"If a class is not declared as either with or without sharing, the current sharing rules remain in effect. This means that if the class is called by a class that has sharing enforced, then sharing is enforced for the called class."


Hmm.  Is the error occurring only in a specific Salesforce instance?  If so, is it in a trial period?


This error is occuring in a managed package, and affect multiple instances, including EE editions, developer editions, and sandboxes.  


I was told by someone on twitter that unless explicitly noted that classes operate With Sharing by default when called from a trigger.  In this case, I have a trigger that calls a helper class that has no sharing declaration.  It's acting like it's With Sharing, since standard users that trip the trigger cause this SOQL error but Sys Admins that trip the trigger have no issue.  


I swear that this is a change in default behavior.  I thought that triggers and helper classes with no sharing declaration were in system context and without sharing by default.  I think this is not the case though now, since when I changed the managed package class to Without Sharing, the problem was resolved.  


This apex syntax around sharing needs a makeover.  In my opinion, With Sharing or Without Sharing should be required on all classes since it's cryptic what no sharing declaration actually means. 


Glad it was resolved.


Hi, I am unclear on what the resolution was for the Organization not supported problem? Are you guys able to get past this? We are using the REST API and trying to query a user's Organization ID. We see lots of loose references on the web about getting this from the SOAP UserInfo object, but we're trying to find out how to do it through REST. Any pointers?



yan at crowdcast dot com