1
SELECT Id, Name,(Select OldValue, NewValue From Histories) FROM CustomObject__c

I understand that I can get the sequence of the values changed for that particular field .

Is it possible to get the values which were present in a certain time range? e.g value of the field during Q2 2015

4

You could also use Date literal . check the document you have so many option like QUARTER, MONTHS, YEAR etc. You may want to use these in your soql

Like get the history records where created date greater than Last Quarter

SELECT ID, (SELECT Id,Field, OldValue, NewValue 
              FROM Histories where field ='Status' 
               AND Createddate > LAST_QUARTER)  
  FROM CustomObject__c

Updates

Check field value for particular time

SELECT ID, (SELECT Id, Field, OldValue, NewValue 
                  FROM Histories where field ='Status' 
                   AND Createddate > LAST_QUARTER
                   AND Field = 'CustomField__c'
                   AND NewValue = 'SOMETHING')  
 FROM CustomObject__c
  • Thank you . How can I access the values in the History column of the query result ? e.g I need to check if during that time period , field value is X or not ? – Vanilla_Sky May 27 '16 at 7:35
  • @Vanilla_Sky check my updates. – Ratan Paul May 27 '16 at 7:39
  • A question on this . Is there any way to check whether the value of a field!= 'XYZ' on last day of the Quater/Month last year? – Vanilla_Sky Jun 1 '16 at 7:09
  • @Vanilla_Sky just use NewValue != 'SOMETHING' and createdDate prev year – Ratan Paul Jun 1 '16 at 7:20
  • I want to check dynamically whether last day of last Year this quarter had a value !=XYZ . Created Date won't help in this case I suppose? Using Last day of that quarter would be wrong – Vanilla_Sky Jun 1 '16 at 7:33
1

The CreatedDate in Histories object is the date on which the modification was done.

 (Select OldValue, NewValue, CreatedDate From Histories)

Based on that date, you can play with Date ranges as you require.

1

Try giving the WHERE clause on the 'CreatedDate' field.

Example :

SELECT ID, (SELECT Id,Field, OldValue, NewValue 
              FROM Histories where field ='Status' 
               AND Createddate > 2015-03-31T23:59:59.000Z)  
  FROM CustomObject__c

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.