Salesforce Flows are a versatile tool for automating business processes, but they become even more powerful when you incorporate the History object into your workflow. The History object allows you to track changes made to a record over time, providing valuable insights into data modifications, and enabling you to create audit trails and historical reporting. In this blog post, we'll dive deep into the History object in Salesforce Flows, exploring its capabilities and how to use it effectively.
Understanding the History Object
The History object in Salesforce is a system object that stores historical data for a selected set of standard and custom objects. It captures changes made to records, such as when a field is updated, and stores these changes in a related list on the record's detail page. This feature is invaluable for compliance, auditing, and tracking data changes over time.
The field history tracking should be enabled for the object before you work with it in flows. For more information, click here.
Why Use the History Object in Flows?
Integrating the History object into your Salesforce Flows can yield several benefits:
1. Audit Trails: It provides a comprehensive audit trail of changes made to a record, showing who made the changes and when. This is crucial for maintaining data integrity and meeting regulatory compliance requirements.
2. Historical Reporting: You can build historical reports and dashboards to analyze data changes and trends over time. This helps in making data-driven decisions and identifying patterns.
3. Data Validation: By comparing current and previous values, you can implement data validation rules within your flows, ensuring data consistency and accuracy.
4. Process Automation: Trigger specific actions or notifications based on changes to records. For instance, you can automatically notify a manager when a high-value opportunity is modified.
Implementing the History Object in Salesforce Flows
Now, let's explore how to use the History object in Salesforce Flows with the help of an example. I will be solving the requirement in this blog “If the status for Lead is Working - Contacted for more than 4 days an email should be sent to the manager. If a mail is sent and the status is not changed after 6 days another mail should be sent. ”I am using two different email templates(Lead Escalation Delay- 6 Days, Lead Escalation Delay- 4 Days) for both escalations. You can use any template/email alert as per the client's requirement.
Requirement understanding
For example, look over these scenarios and results to understand better.
Scenario 1:
Created Date: 21/09/2023
Current Date: 27/09/2023
Resource Interval4Days: 23/09/2023
Resource Interval6Days: 21/09/2023
First outcome: True[21/09/2023(created date) <= 21/09/2023(Interval6Days)]
Result: 6 days escalation email
Scenario 2:
Created Date: 22/09/2023
Current Date: 27/09/2023
Resource Interval4Days: 23/09/2023
Resource Interval6Days: 21/09/2023
First outcome: False[22/09/2023(created date) <= 21/09/2023(Interval6Days)]
Second outcome: True[22/09/2023(created date) <= 23/09/2023(Interval4Days)]
Result: 4 days escalation email
Scenario 3:
Created Date: 25/09/2023
Current Date: 27/09/2023
Resource Interval4Days: 23/09/2023
Resource Interval6Days: 21/09/2023
First outcome: False[25/09/2023(created date) <= 21/09/2023(Interval6Days)]
Second outcome: False[25/09/2023(created date) <= 23/09/2023(Interval4Days)]
Result: Default(Nothing will execute)
Let’s get started. Have a look at the image below. This is how the flow should turn out at the end.
Step 1: Create a schedule-triggered flow on the Lead object with the condition Status equals Working - Contacted.
Step 2: Add the Get Records element(Status_Field_History). Choose an object as Lead History. Add two conditions as the Field Equals Status and LeadId Equals Record>Lead Id. This element is supposed to fetch the changes done in the Status field for the current Lead record.
Step 3: Create two formula resources. Interval4Days and Interval6Days to calculate the interval from the current date. For Interval4Days enter the formula “{!$Flow.CurrentDateTime} -4” and Interval6Days enter the formula “{!$Flow.CurrentDateTime} -6”.
Step 4: Add decision element(Check the status is working for more than 4 days). This element is supposed to check whether a lead status has been working - contacted for more than 4 days.
A. First outcome: {!Status_Field_History.CreatedDate} Less than or Equal Interval6days
B. Second outcome: {!Status_Field_History.CreatedDate} Less than or Equal Interval4Days
C. Default outcome
Step 5: Add two email actions to each outcome as follows. The first outcome with Lead Escalation Delay- 6 Days email alert and the Second outcome with Lead Escalation Delay- 4 Days email alert. Populate Record ID with the current lead record ID {!$Record.Id}.
Conclusion
The History object in Salesforce Flows is a powerful tool for tracking and managing data changes, making your business processes more transparent and compliant. By implementing it effectively, you can build robust audit trails, historical reports, and data validation mechanisms within your Salesforce environment. So, explore the potential of the History object and unlock a new level of data management in Salesforce Flows.
If you'd like to see the code and resources used in this project, you can access the repository on GitHub.To access the AVENOIRBLOGS repository, click here. Feel free to explore the code and use it as a reference for your own projects.
Thank you! You can leave a comment to help me understand how the blog helped you. If you need further assistance, please get in touch with us at Reach us. You can click "Reach Us" on the website and share the issue with me.
References
https://help.salesforce.com/s/articleView?id=sf.tracking_field_history.htm&type=5
https://help.salesforce.com/s/articleView?id=sf.tracking_field_history_for_custom_objects.htm&type=5
https://help.salesforce.com/s/articleView?id=sf.tracking_field_history_disabling.htm&type=5
https://help.salesforce.com/s/articleView?id=sf.field_audit_trail.htm&type=5
Blog Credit:
D. Khare
Salesforce Developer
Avenoir Technologies Pvt. Ltd.
Reach us: team@avenoir.ai
Comments