5

I've seen this error before many times, occasionally even in my own code.

Entity is not api accessible

It seems like often the compiler thinks you're looking for a standard object and it can't find the schema for it. This phenomenon can be observed with a few different keywords that I know of. Simple repro:

service.doSomething();
project.doSomething();

But then, sometimes the compiler is smart enough to realize it's just an undefined variable:

bogus.doSomething();

Variable does not exist: bogus


Neither project nor service are Reserved Keywords. Neither one is a Standard Object. So what defines when the compiler throws one error instead of the other? Is there a comprehensive list of entities that will not be seen as undefined variables?

  • 1
    Seen this a several times as well. Started happening about 6 months ago. Makes debugging a pain. If I remember next time it happens I will post here. – Eric Aug 18 '16 at 2:10
  • Right, I've seen it many times. These are the only two entities I remember right now, but I'll add any others if they come to me. – Adrian Larson Aug 18 '16 at 2:11
4

Service and Project are actually Schema objects, just not ones that you have access to. Saleforce tries to resolve SObject types before failing completely. See the Type Resolution documentation for more details on how names are resolved. If you get to Step 4, and the object happens to be something that really does match an SObject, you'll get that error. One of the most common examples I have is:

Product2 p = new Product();

This simple typo produces the same error; Product was deprecated many versions ago, and isn't available in newer code. These reserved objects are either (a) deprecated objects, (b) features not enabled in your org, (c) features not yet exposed in future releases, or (d) features used internally by Salesforce or otherwise support the application indirectly.

This error occurs on "hidden" objects simply because the standard schema is actually the same for all orgs; you can consider them "hard-coded" into the core platform. In fact, I've actually written some code that exposes hidden objects by the key prefix, which is how I found things like:

Key    Prefix
-----+------------------------
1gh  | GitHubRepositoryLink
1gp  | GitHubPushOperation
1rp  | Repository
4sr  | Service
4st  | ServiceDataType
4sv  | ServiceVersion

I don't know if they're new (pending) features, or things used internally, but you can find some interesting things if you did deep enough. Usually, the best you can do is to pretend the error is the same as an "unknown variable" error, unless you're expecting to have your deployment work and it doesn't (this usually means you haven't enabled a feature in your org), in which case, you'll want to Google what the object does and what feature it's used for.

Interestingly, it appears that Project doesn't have a key prefix, which probably means it shares its key prefix, which is the only reason I know of why my code would fail (or, it's actually even more hidden than I thought).

  • Can you provide references on how SF compiles Apex and VF. This might throw some light on this class parsing issues? – Pranay Jaiswal Aug 18 '16 at 3:52
  • @PranayJaiswal See the Type Resolution link, which explains the resolution order. Basically it goes "scalar", "local type", "class type", "sobject type." The resolution for "entity is not org-accessible" occurs before "variable not found." – sfdcfox Aug 18 '16 at 4:02
  • That's weird they're not in the SOAP API Developer Guide. I have a rough idea, but can you include the code you used to find these objects? – Adrian Larson Aug 18 '16 at 14:21
  • @AdrianLarson login.salesforce.com/packaging/… Might take a little to become active. – sfdcfox Aug 18 '16 at 23:14
  • I'm guessing you just loop through all possible prefixes? Is that 36^3 possibilities or is uppercase allowed? – Adrian Larson Aug 18 '16 at 23:26
1

I just came across another common instance of the Entity is not api accessible error in this post. If you have an object whose OWD Sharing Setting is Public Read/Write, then accessing share records for that object will throw this error.

Example:

MyObject__share shareRecord = new MyObject__share();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.