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.

  • So, what exactly are you having a problem with/question about ? – Samuel De Rycke Mar 3 '14 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 Mar 3 '14 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. – Samuel De Rycke Mar 3 '14 at 12:07
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.