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
Kristen Aldrich 14Kristen Aldrich 14 

Error System.QueryException Duplicate fields selected

I received 100+ error emails overnight that all look a bit like what I've copied/pasted below. I'm not a developer and am trying to figure out how to fix this. Luckily it's in our Partial Sandbox, so is not affecting our Production org but still, would like to get to the bottom of it. From what I've read, a duplicate field error like this means there are fields with identical API names and the query errors out essentially not knowing which one to use/reference. I do see fields with the label "Amount" with identical APIs but nothing that has changed or been added in the last couple days, which makes me think why would this error suddenly come up now. Where do I find the query? How do I identify which Amount field it's looking for? And where/how do I update the query to fix this?

Error Type: System.QueryException
Error Date: 2019-12-13 04:15:20
Message: "npsp__Largest_Soft_Credit_Date__c,npo02__LastOppAmount__c,npo02__LastCloseDate__c,npo02__LastMembershipAmount__c
^
ERROR at Row:1:Column:350
duplicate field selected: Amount

Rollups State:"
Context: CRLP.ContactSoftCredit

Stack Trace:
No stacktrace available at the time of saving the record. (npsp)
Foram Rana RForam Rana R
Hi Kristen,

You got this error bcs : two fields have the same API name
Example :

Account obj  = [Select Id, Name, Name from Account];
Here Name  field is used twice then also we are getting two fields have the same API name Error.
Check your select query and let me know your review.
Mark it as best answer if you resolved it.

Thanks,
Foram Rana

 
Kristen Aldrich 14Kristen Aldrich 14
Thanks Foram. Where can I find the select query to edit it?
Foram Rana RForam Rana R
In your apex class related to your functionality.
there is twice the Amount field in your select query.
Kristen Aldrich 14Kristen Aldrich 14
Thanks Foram. The apex class is from a managed package, and when I look at it the code area is blank. How should I address that? 
Shraddha D GuptaShraddha D Gupta
Hi Kristen,

Were you able to resolve this issue?

I am also getting similar issue as below-

SBQQ.OpportunityAfter: execution of AfterUpdate caused by: System.QueryException : duplicate field selected: SBQQ__Status__c(SBQQ) No record updated

and not sure how to resolve this. 

Any help would be much appreaciated. 

Thanks!
Kristen Aldrich 14Kristen Aldrich 14
Hi Shraddha,
I never got an answer or resolution but the issue hasn't come up again since December 2019.
Shraddha D GuptaShraddha D Gupta
Hi Kristen,

Oh okay.. great it is. 

But in our case we are getting error a lot in sandbox environment. 

Thanks!
skuiderskuider
I think I know the answer as I just got it and fixed it. Do you have any child records being called an API name the same as a Lookup/Master-Detail relationship name? Here's my example before and after.
SELECT Id,Cross_Section__r.Name,(SELECT Id FROM Cross_Section__r) FROM SAS_Product_Type__c
See that I have "Cross_Section__r" twice but on two objects. The SOQL should not fail on this, but the engine fails thinking there are two.
SELECT Id,Cross_Section__r.Name,(SELECT Id FROM Cross_Sections__r) FROM SAS_Product_Type__c
Note the extra "s" in the "(SELECT Id FROM Cross_Sections__r)"

Can this be my first Best Answer?
Bilal Aslam 26Bilal Aslam 26
Today, I have encountered same issue, the problem was same field name was being used twice in SOQL.
Richard Fiekowsky 3Richard Fiekowsky 3
You can get the same field of another object twice if they are specified with different lookups from the object that you Select. For instance,
Select Opportunity__r.PrimaryContact__c, PreviousOpportunity__r.PrimaryContact__c From SalesLog__c
Tip - To find the duplication: if you are using Dev Console, copy your code into an editor. The Find function in DC doesn't work the way one would expect.