Dupplicate Field Selected Exception - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
Varun ChopraVarun Chopra 

Dupplicate Field Selected Exception


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(); 
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 filed lable but is there anything that we can do in our code to fix this issue ?

Thanks In Advance !

vetriselvan manoharanvetriselvan manoharan
I think renaming the label is the only option available. Do post this question in developer forums. You may get quick response

Sindoora GopagoniSindoora Gopagoni
Post this query in the developer forum.
Here is the link

Also check in the code of querylocate.probably in your code some where you might have refering to the field twice.
Madhanprabhu ThangaduraiMadhanprabhu Thangadurai
Database.Query() in managed package class appends package namespace to local fields which are NOT part of managed package

Knowledge Article Number 000228097
If a custom field is created on an installed managed package custom object, which has the same API name as one of the custom fields in the package, using database.query() from within the package having both these fields (package field and local custom field) in the query string will throw

 System.QueryException: duplicate field selected: <NAMESPACE>__<FIELD>__c

According to the below documentation, when looking at identifiers, the parser considers the namespace of the current object and then assumes that it is the namespace of all other objects and fields unless otherwise specified


Change the custom field API name to different from installed package custom field API name
Vinay ChaturvediVinay Chaturvedi
+1 MadanPrabhu,
You are left with two options:
Either change the API name of field or restraucture your code in such a way that you dont use dyanmic soql(
Database.query method)

Also there is nothing to do with label beacause label even if they are not unque will not throw error.
MiglenaMiglena (Salesforce.com) 
Hello Varun,

The community has provided you with some great suggestions and guidance. I hope you were able to get this resolved. Please take a moment to mark the most helpful post as "Best Answer" to close off this string and help others in the community with similar questions. Should you require additional help, please do not hesitate to ask. Thank you all for your contribution to Success Community.
Omar RodriguezOmar Rodriguez
The reason we are encountering this issue in our product version 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. 

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.
Sindoora GopagoniSindoora Gopagoni
Hi Varun,
Have you find the answer .Iaf yes mark the best answer thi will help others .
Deepali KulshresthaDeepali Kulshrestha
Hi Varun,
Please refer to the link below:

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha