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
asadim2asadim2 

Bugs with duplicate objects (local and packaged)

Scenario
We have a package consisting of objects PKG__Object__c and PKG__Parent__c, and class PKG.ClassA. This package is installed inside a client org. The client org also has an object called Object__c (same name as the packaged object) with a lookup to PKG__Parent__c called Parent__c.

Issues
1. Global method PKG.ClassA.runQuery1() runs a dynamic query. Said method is called from a custom Apex class in client org. The resulting query looks like this: "select Id from Object__c where Id in :ids". But SF treats it as PKG__Object__c, and if we block access to the packaged object, SF throws an exception: 
sObject type 'PKG__Object__c' is not supported. (PKG)

2. Global method PKG.ClassA.runQuery2() runs a dynamic query. Said method is called from a custom Apex class in client org. The resulting query looks like this: "select Id, (select Parent__c from Objects__r) from PKG__Parent__c where Id in :ids". But SF throws an exception: 
No such column 'PKG__Parent__c' on entity 'PKG__Object__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name.

Is anyone aware of this? This is causing major issues as we upgrade historic clients.

ShashankShashank (Salesforce Developers) 
This could be due to how the dynamic query is being constructed. Would you be able to post some code which builds the dynamic query?