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
Varun ChopraVarun Chopra 

Duplicate Field Selected Exception:

Hi 

I am facing a wired issue in my clients org. There are two fields in the clients org with same label suppose ABC. 

One from our package (xyz )and one in their own org.  Our code is executing dynamic query using salesforce  
Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap()  method.
 
Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();
    
 string fieldnames=' ';
 for(String s : objectFields.keySet()) 
 {
   s = objectFields.get(s).getDescribe().getName(); 
   fieldnames+=s+','; 
 }
        fieldnames=fieldnames.substring(0,fieldnames.length()-1);   
string query=  'SELECT '+fieldnames +' from xyz_sfObj__c';
List <xyz_sfObj__c> sfObjData = Database.query(query);

//return fieldnames;

When the above query is executing salesforce is throwing the following error:

Duplicate Field Selected: xyz_ABC__c

For now I hvae fixed it by renaming the field label but is there anything that we can do in our code to fix this issue ?

Thanks In Advance !
James LoghryJames Loghry
Varun, try changing "getName" to "getLocalName" to see if that helps.
Omar Rodriguez 33Omar Rodriguez 33
The reason we are encountering this issue in our  product is because we upgraded to a newer SFDC API version based on Salesforce's recommendation.

Now this API version is not resolving the conflict between managed object and custom object with same name with namespace.

As per what I read, , Customer should not have a field with same name (packaged and unmanaged) on the same object, and is not recommended practice, hence their suggestion is to ask Customer to update Custom fields that have duplicate name. You can find more details here:
https://success.salesforce.com/answers?id=90630000000DNMeAAO

We are also aware that by the change in platform behavior and significant effort on Customer side to update fieldname is not feasible due to impact to other areas like workflow rules, custom apex classes, integration etc.