I'm creating lookup fields on an object dynamically using the Metadata API, saving the name of a field as a Custom Setting and building queries dynamically. This works perfectly, but there is a conflict with the same name fields which are already there with a namespace prefix.
Let's say I have an object in my package called
with a field
For instance, I am building a query like this:
String q = 'SELECT ' + Transaction__c.Subscription__c.getDescribe().getName() + ',' + Transaction__c.SObjectType.getDescribe().fields.getMap().get('Subscription__c') + 'FROM etc etc etc';
(I already created in the org where the package is installed a field called
I expect to have something like this:
SELECT prefix__Subscription, Subscription__c FROM etc etc etc
However what I'm getting is this:
SELECT prefix__Subscription, prefix__Subscription__c FROM etc etc etc
i.e. a duplicate field in the query. The system thinks on
that I'm interested in the namespaced
Subscription__c field, however I want to get the un-namespaced one.
Do anybody have an idea have to do this? Please note that if there is NO conflicts between the namespaced and un-namespaced field names (a field name like 'A_Completely_New_Lookup__') everything works as intended, so the code from the package can get the fields which are created in the org.