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 !