Cheatsheet

Histories

Estimated reading: 1 minute 38 views
				
					SELECT Id, KVKK_Permission__c, 
       KVKK_ETK_Permission_Asked__c, 
       Primary_Contact_KVKK__c, 
       (SELECT Field, OldValue, NewValue, CreatedDate 
        FROM Histories) 
FROM Account 
WHERE Id = '0010Y0x0xxVaabBQA' 

				
			
				
					SELECT Id, Field, OldValue, NewValue, CreatedDate
FROM OpportunityFieldHistory
WHERE Field = 'Dealer__c' LIMIT 100
				
			

Fetch updated records by a certain field update

				
					List<OpportunityFieldHistory> historyRecords = [
        SELECT Id, Field, OldValue, NewValue, CreatedDate
        FROM OpportunityFieldHistory
        WHERE Field = 'Dealer__c'
        LIMIT 1000
];

System.debug('historyRecords.size()=' + historyRecords.size());
List<OpportunityFieldHistory> filteredHistoryRecords = new List<OpportunityFieldHistory>();

for (OpportunityFieldHistory record : historyRecords) {
    if (record.OldValue == 'old value' && record.NewValue == 'new value') {
        filteredHistoryRecords.add(record);
    }
}

// Now you have the filtered results
System.debug(filteredHistoryRecords.size());
System.debug('Filtered History Records: ' + filteredHistoryRecords);
				
			
Share this Doc

Histories

Or copy link

CONTENTS