Formula fields can't be enabled for history tracking. There's a workaround where a new date/time field has to be created for every formula field with formula as now() which would be updated via a field update for a workflow on the formula field (onchange of the formula field). Are there any other workarounds for this? Also, instead if the fields on which the formula fields are dependent are marked would it serve the purpose?
[SalesForce] History tracking for Formula fields
Related Solutions
Create an object called AccountHistoryTracking and fields like APIName__c,OldValue__c,NewValue__c then create a fieldset on Account called'HistoryTracking' with the fields you want to track on Account and then write below code to track history on account.This way you don't need to worry about history tracking limit per object.
trigger AccountHistoryTracker on Account (after update) {
final List<Schema.FieldSetMember> trackedFields =
SObjectType.Account.FieldSets.HistoryTracking.getFields();
if (trackedFields.isEmpty()) return;
final List<AccountHistoryTracking__c> fieldChanges =
new List<AccountHistoryTracking__c>();
if(!trigger.isUpdate)
return;
for (Account newAccount : trigger.new) {
final Account oldAccount = trigger.oldmap.get(newAccount.Id);
for (Schema.FieldSetMember fsm : trackedFields) {
String fieldName = fsm.getFieldPath();
String fieldLabel = fsm.getLabel();
if (newAccount.get(fieldName) == oldAccount.get(fieldName))
continue;
String oldValue = String.valueOf(oldAccount.get(fieldName));
String newValue = String.valueOf(newAccount.get(fieldName));
if (oldValue != null && oldValue.length()>255)
oldValue = oldValue.substring(0,255);
if (newValue != null && newValue.length()>255)
newValue = newValue.substring(0,255);
final AccountHistoryTracking__c accountHistory =
new AccountHistoryTracking__c();
accountHistory.name = fieldLabel;
accountHistory.apiName__c = fieldName;
accountHistory.User__c = newAccount.Id;
accountHistory.ChangedBy__c = UserInfo.getUserId();
accountHistory.OldValue__c = oldValue;
accountHistory.NewValue__c = newValue;
fieldChanges.add(accountHistory);
}
}
if (!fieldChanges.isEmpty()) {
insert fieldChanges;
}
}
You can track upto 60 fields per object and it should be same for all sandboxes.
Please check below info
https://www.salesforce.com/blog/2015/07/introducing-salesforce-shield.html
Field Audit Trail gives customers a time machine so they can go back in time and see the state and value of their data on any date, at any time. It expands what is currently available with Field History Retention, giving customers up to 10 years of audit trail data for up to 60 fields per object.
https://help.salesforce.com/HTViewHelpDoc?id=field_audit_trail.htm&language=en_US%E2%80%8B
The HistoryRetentionPolicy is automatically set on the above objects, once Field Audit Trail is enabled. By default, data is archived after 18 months in a production organization, after one month in a sandbox organization, and all archived data is stored for 10 years.
http://resources.docs.salesforce.com/202/21/en-us/sfdc/pdf/field_history_retention.pdf
Best Answer
You can use following options: