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
MattWelchMattWelch 

SOQL query returning same row twice

In our org, we have two users whose records are returned twice when called via APEX, or via the API.

If this SOQL is executed:

Selected Id, LastViewedDate, LastReferencedDate from User where Id='005xxxxxxx'

is executed in our org, you can see where the same result is returned twice. In fact, if you include a "limit 1" on the end of that SOQL query, it STILL returns those two, identical results.

If both LastViewedDate and LastReferencedDate are removed from the query, only one result is returned for each record, which is the expected, normal behavior.

Anyone else seen anything strange like this?
Cory CowgillCory Cowgill
I can not recreate. I get only 1 row back.

User-added image

Are you sure you are querying the correct object?

Also if I copy your SOQL above it does not work becuase "Selected" is not a keyword it should be Select.

If you post the actual code snippet that may help.
MattWelchMattWelch
Ooops. Yeah. The "selected" was a typo.

I am querying the user object with this exact SOQL, both via anonymous APEX (through SOQLExplorer) and in an Apex class, and get the same, two-rows-for-one-record returned in both cases:

Select Id, LastViewedDate, LastReferencedDate from User where Id='005xxxxxxx'
Cory CowgillCory Cowgill
How many characters is the UserID? Is it 15 or 18? I assume the xxxxxx is you just masking the input right.
MattWelchMattWelch
Yeah, I'm just masking the id. I've tried both the 15 and 18 character Id varieties. In fact, I've left the WHERE clause off entirely and and I still see that this user's record is returned twice, along with all the other users' records that are returned once.
Norm Sherman SFNorm Sherman SF
What is surprising is you said 2 rows are returned, even with the LIMIT 1 clause. That sounds technically impossible.

Have you tried the same query inside Data Loader?

MattWelchMattWelch
Odd. LexiLoader (the Mac version of Data Loader) doesn't even show the LastViewedDate and LastReferencedDate fields. Must be an API version issue.
Cory CowgillCory Cowgill
As Norm Sherman said if you put LIMIT 1 this should be impossible, and I can't recreate this.

Instead of UserID and you query on UserName (which should also be unique).

Select Id from User where UserName ='TheUserID@TheUser.com"......

You can try opening a SFDC Support Ticket assuming you have support. 
ELEL
I am seeing a similar thing, but it's happening on a custom object.  Same fields trigger the problem, it only happens for one Id, and even with the LIMIT 1, it still returns two.  Did you figure out how to fix it?