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
CliffordClifford 

SOQL query to return username from history object

We have a custom object that has a corresponding history object to track changes.  I am trying to write a query to retrieve the history information, including username in as efficient a manner possible since I am going through the API.  I can write a query such as:

 

Select createdbyid, newvalue, oldvalue from My_Object_History__c

 

But what I really want is something like the following so I do not have to round trip back to the server to get the username:

 

Select (username from user where id = createdbyid), newvalue, oldvalue from My_Object_History__c

 

Can someone help and let me know if this is possible and if so, how?

RickyGRickyG
Clifford -

I used the salesforce.schema tool in the Force.com IDE to come up with the following SOQL statement by simply clicking -

Select c.OldValue, c.NewValue, c.CreatedBy.Username, c.CreatedById From Candidate__History c

for the history on the Candidate__c custom object. Would this work for you?
CliffordClifford
Thanks Rick, I thought I had tried something similar but without any luck.  That will do the trick.