+ 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?