Does anybody see what is the mistake in this snippet of code?
List <AccountHistory> accHistory = [SELECT Id, Account.name, Field, OldValue, NewValue
FROM AccountHistory
WHERE AccountId = 'asada978asd'
AND field ='Primary_Phone__c'];
List<AccountHistory> accHistList = new List<AccountHistory>();
if(accHistory.size() > 0) {
for( AccountHistory accHis : accHistory){
accHistList.add(accHis[0].NewValue);
}
}
When I try to run it I get this error:
"compileProblem": "Expression must be a list type: AccountHistory",
"compiled": "false",
"exceptionMessage": "",
"exceptionStackTrace": "",
What I am trying to do here is I try to grab all values of phone that were changing through the history, put them into list, sort that list and then to be able to say "Ok I want to grab only last and before last value".