Efficient way to find error causing "Save Error: Entity is not org-accessible"
According to the Apex developer's guide:
If the expression ends with a set of parentheses (for example, name1.name2.[...].nameM.nameN()), the Apex parser evaluates the expression as follows:
- The parser first assumes that name1 is a local variable with name2 - nameM as field references, and nameN as a method invocation.
- If the first assumption does not hold true:
• If the expression contains only two identifiers (name1.name2()), the parser then assumes that name1 is a class name and name2 is a method invocation.
• If the expression contains more than two identifiers, the parser then assumes that name1 is a class name, name2 is a static variable name with name3 - nameM as field references, and nameN is a method invocation.
- If the second assumption does not hold true, the parser then assumes that name1 is a namespace name, name2 is a class name, name3 is a static variable name, name4 - nameM are field references, and nameN is a method invocation.
- If the third assumption does not hold true, the parser reports an error.
In your case the parser has made it to point 4, but hasn't reported a particularly helpful error. It seems likely that the assumption is that invoice is an sobject or class, and that getSObject() is a static method on this sobject/class. Rather than tell you that this sobject/class doesn't exist, it falls back on the assumption that this must be something that just happens not to be visible to your org configuration or license. I think that in the majority of cases the errors reported in this situation are likely to be unhelpful as the parser fundamentally can't determine what you are trying to do, so it has a one size fits all message.
The first few times this happened to me it was with sobject names (Quote was one) so I assumed it that was related to the use of a real sobject name, but I've also had it happen where I've missed out the namespace for a system class (e.g. Action rather than ApexPages.Action).
The biggest problem when I've hit this is that a lot of the time the error is reported as 'line 1 column 8' or is missing completely. If that is the case I just go back over my recent changes (using the Force.com IDE) compare with and try to narrow down the areas to look in, which isn't really any different to what you are doing.