function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rick MacGuiganRick MacGuigan 

History tracking merge fields

I am tracking changes to a custom field called AMBest on the account record. This value is updated from Informatica cloud via AMBest feed data in Oracle. If this value changes I need to report on the change in a chatter post via process builder. Field history tracking is enabled for the AMBest field. There doesn't seem to be a way to use a merge field to pick the most recent value for account history for ths value. Any ideas ? 
jigarshahjigarshah
Rick,

Writing Apex Triggers, Process Builders or Workflows on History objects i.e. the AccountHistory object is unavailable. Hence, in order to identify the most recently modified value for the AMBest field, on Account you will need to use the following approach.

1. Create a Scheduled Apex Job that runs every 1 min (adjust this frequency based on your need) and checks for the recently modified Account records basis the LastModified DateTimeStamp.

2. You can then iterate over each of those Account records to query the most recent value of the AMBest field. You can use the below SOQL query.
Select Id, Field, OldValue, NewValue, Createddate From Account__History 
where Field = 'AMBest__c' and ParentId = :<AccountRecordId> 
Order by Createddate DESC

3. Pick the NewValue of the record at the 0 index and stamp it on a custom field AMBestRecentValue__c on Account. You can keep it hidden on the layouts and just use it inthe backend for processing.

4. Write a Process Builder on Account that fires when the AMBestRecentValue__c field value changes and posts a notification to Chatter.

The above approach is near real time in nature and depends on the frequency of the scheduled Apex Job to search for the modified Account records.