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
Craig CoulterCraig Coulter 

Log previous day field values

Hi All,

We want to log certain field values from an opportunity, some of those fields are formula fields, so we can see what those field values were over time and have them time stamped. I was going to try and achieve this by creating a custom object (Daily Performance for example) and create a new record daily if one of those fields values change, so the new record will hold the previous values and we have a reportable historical log.

Would this be the best way to achieve this, or is there a better, more efficient way to do this?

Thanks

Craig
SubratSubrat (Salesforce Developers) 
Hello Craig ,

Creating a custom object (e.g., "Daily Performance") to log historical field values from an Opportunity is a valid and practical approach. It's commonly known as "Field History Tracking" or "Historical Tracking" in Salesforce. This approach allows you to have a historical log of field changes with timestamps, providing you with an audit trail of the Opportunity's field values over time.

Here's how you can implement this approach:

Create Custom Object: Create the custom object ("Daily Performance") with fields to store the relevant information, such as Opportunity ID, field values, and a timestamp.
Trigger: Write an Apex trigger on the Opportunity object to capture changes in the specific fields you want to track. When these fields are updated, the trigger creates a new record in the "Daily Performance" object, storing the previous values along with the timestamp.

Overall, this approach is widely used and effective for tracking historical changes to specific fields in an Opportunity record. However, it's essential to consider the data storage implications and only track the fields that are crucial for your reporting and analytics needs. 

Another alternative to this approach is to use the Salesforce built-in "Field History Tracking" feature. This feature allows you to track changes to standard and custom fields on specific objects (including Opportunity) without the need for custom code. It automatically logs field history in a system audit trail, which can be accessed through the object's "Set History Tracking" settings. However, this feature has some limitations, such as not supporting formula fields and having a limited retention period for historical data (up to 18 months).

References : 
https://salesforce.stackexchange.com/questions/279946/how-to-create-a-record-histroy-c-custom-object-with-old-values-and-new-valu

https://help.salesforce.com/s/articleView?id=sf.tracking_field_history_for_custom_objects.htm&language=en_US&type=5


Hope this helps !
Thank you.
Craig CoulterCraig Coulter
Hi Subrat,

Thanks for the reply. I will look into that.

Would it be possible to do a similar thing without an Apex trigger, like using a Flow for example?

Thanks

Craig