I have a list of Market__history that track the changes in my custom object market__c Since I am manipulating a lot this object instead of making multiple SOQL call I made one big SOQL call to extract ALL the history data for my specific markets ans now I can manipulate the data without calling too much time the servers.
What I would like to acheive is extract that LAST CREATED history object for each market but I am not sure how to acheive that.. I tried [-1] like in python without success
any idea ???
My code look the following;
extract all history data :
List<Market__History> MarketHistory = [SELECT id, ParentId, OldValue, NewValue, Field, CreatedById, CreatedDate FROM Market__History where ParentId IN :RelevantMarketData];
2)looping my market and get the history data:
for(Market__c marketItem: RelevantMarketData ){
List<Market__History> MarketHistoryList = new List<Market__History>();
for(Market__History marketHistoryItem: MarketHistory){
if(marketHistoryItem.parentId == marketItem.id && marketHistoryItem.CreatedDate >= begDate && marketHistoryItem.CreatedDate >= endDate ){
MarketHistoryList.add(marketHistoryItem);
}
}
if(MarketHistoryList.size()>=1){
//system.debug('test');
system.debug('test: ' + MarketHistoryList.last());
}
}