0

I'm not finding a way to get the latest updates Scenario :

There are three people which is assigned to a given lead.

Lead name : L1

User Name is John,Adam,Charles

Created Date    NewValue    OldValue    Lead
01/03/2014  Adam    John    L1
03/03/2014  Charles Adam    L1
07/03/2014  John    Charles L1

How do we fire a soql on L1's leadhistory object so that we get only below result

07/03/2014  John    Charles 

Please help

5
  • possible duplicate of SOQL on LeadHistory object Commented Mar 6, 2014 at 12:56
  • Thanks Samuel. This is different scenario now As that didn't fulfill the case and still stuck.
    – JJoseph
    Commented Mar 6, 2014 at 12:59
  • It looked like a different version of the same question to me. apologies. I have re-tracted my close vote. Commented Mar 6, 2014 at 13:05
  • Yes its the same version but this scenario is more specific and wanted to say the same thing in previous one. May be you have taken it in different way. Please suggest the efficient way to get a query. Thanks
    – JJoseph
    Commented Mar 6, 2014 at 13:10
  • The example in this question did help, see my answer. Commented Mar 6, 2014 at 13:12

2 Answers 2

0

You can use a combination of ORDER BY and LIMIT on your SOQL query to get that result.

Not much different than your other question on how to query lead history

SELECT CreatedById,CreatedDate,Field,Id,LeadId,NewValue, oldvalue 
FROM LeadHistory 
WHERE field = 'Owner' AND LieadId ='XXXXXXXXXX'
ORDER BY CreatedDate DESC
LIMIT 1
5
  • Thanks Samuel. But here I don't want to use LIMIIT.Is there any other way to get the same result ?
    – JJoseph
    Commented Mar 6, 2014 at 13:12
  • Can you explain why you do not want to use limit ? (Because you want to query for a bulk amount of leads at the same time ?) Commented Mar 6, 2014 at 13:13
  • Thanks again Samuel .I did the same query with the LIMIT. But i'm looking for a more efficient query. Is there any other way of getting same result . Help again will be appreciated.
    – JJoseph
    Commented Mar 6, 2014 at 13:18
  • You have to define what you consider "efficient" and what your application context and scenario is. It is very hard to give you the answer to your true question, only knowing half the question. Commented Mar 6, 2014 at 13:25
  • It does give me the latest one. Working on 4 leads only and want to know if there is other way like using aggregate functions like MAX or MIN ?
    – JJoseph
    Commented Mar 6, 2014 at 13:36
0

This query should get only the latest one:

SELECT CreatedById,CreatedDate,Field,Id,LeadId,NewValue, oldvalue 
    FROM LeadHistory 
    WHERE field = 'Owner' AND  LeadID='yourleadid' ORDER BY CreatedDate DESC LIMIT 1 

You must log in to answer this question.

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