0

Need a SOQL query on LeadHistory object to track the date when the Lead owner was changed .Have already enabled Lead History tracking.

Scenario : Suppose there are two lead owners named Lead1 and Lead2 . At present(eg 4th- Mar-2014) Lead1 is the owner. And on 8th- Mar-2014, owner is changed to Lead2.

I need a SOQL to track the Lead Owner between these old date and new date.

3
  • So, what exactly are you having a problem with/question about ? Commented Mar 3, 2014 at 11:59
  • need a SOQL to get the date but I see that there is nothing like old date and new date in workbench.How do I get a query for this.?
    – JJoseph
    Commented Mar 3, 2014 at 12:02
  • you mean the date when the owner changed ? thats a single moment. I've answered based on that interpretation. If that's not what you're asking please update your question with a better/more detailed description of your scenario. Commented Mar 3, 2014 at 12:07

1 Answer 1

2

As soon as field history tracking is enabled, the objectHistory table becomes accessible to soql, as you already indicate in your question.

SELECT CreatedById,CreatedDate,Field,Id,LeadId,NewValue, oldvalue 
FROM LeadHistory 
WHERE field = 'Owner'

This should give you 2 records per field change for this type, one with the text values and one with the salesforce ID values of the owner lookup. The createdDate of the history record is the datetime the ownership on the lead record changed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .